using Common.Infrastructure.Ioc; using Magellan.Framework; using System; using Common.Infrastructure.Messaging; namespace Common.Infrastructure.Mvc { public abstract class CoreController : Controller { private void TrySetMessageToken(ISupportMessageTokens model) { if (model != null && Request.RouteValues.ContainsKey("MessageToken")) model.SetMessageToken(Request.RouteValues["MessageToken"].ToString()); } /// /// Displays the specified view. /// The name of the view is assumed to be the same as the name of the ActionResult method. /// Example: If the name of the action method is ViewCustomers, the view is assumed to be ViewCustomers.xaml and located in the Views directory. /// /// /// Any type that supports . /// supports , so any ViewModel that inherits from supports . /// /// protected virtual PageResult View(ISupportMessageTokens model) { TrySetMessageToken(model); return Page(model); } /// /// Displays the specified view. /// /// Name of the view to display. /// /// Any type that supports . /// supports , so any ViewModel that inherits from supports . /// /// protected virtual PageResult View(string viewName, ISupportMessageTokens model) { TrySetMessageToken(model); if (String.IsNullOrEmpty(viewName)) return Page(model); return Page(viewName, model); } /// /// Displays the specified view. /// /// /// Any type that supports . /// supports , so any ViewModel that inherits from supports . /// /// protected virtual PageResult View() where TModel : ISupportMessageTokens { string viewName = String.Empty; Action processModel = null; return View(viewName, processModel); } /// /// Displays the specified view. /// /// /// Any type that supports . /// supports , so any ViewModel that inherits from supports . /// /// /// This method is called after a new ViewModel has been created and before the view is displayed. /// The method is passed the newly created ViewModel instance. /// Use the method to modify the ViewModel prior to it being bound to the view. /// Example: m => { m.FirstName = "Chris" } /// /// protected virtual PageResult View(Action processModel) where TModel : ISupportMessageTokens { string viewName = String.Empty; return View(viewName, processModel); } /// /// Displays the specified view. /// /// /// Any type that supports . /// supports , so any ViewModel that inherits from supports . /// /// Name of the view to display. /// protected virtual PageResult View(string viewName) where TModel : ISupportMessageTokens { Action processModel = null; return View(viewName, processModel); } /// /// Displays the specified view. /// /// The name of the view is assumed to be the same as the name of the ActionResult method. /// Example: If the name of the action method is ViewCustomers, the view is assumed to be ViewCustomers.xaml and located in the Views directory. /// /// Any type that supports . /// supports , so any ViewModel that inherits from supports . /// /// /// Name of the view to display. /// /// This method is called after a new ViewModel has been created and before the view is displayed. /// The method is passed the newly created ViewModel instance. /// Use the method to modify the ViewModel prior to it being bound to the view. /// Example: m => { m.FirstName = "Chris" } /// /// protected virtual PageResult View(string viewName, Action processModel) where TModel : ISupportMessageTokens { var model = TypeResolver.Get(); if (processModel != null) processModel(model); return View(viewName, model); } } }