I'm currently working on a portal using jquery portlets/sortable/draggable that also includes a content management system, all in MVC2. Only administrators are able to change the layout/content of the site currently.
Each view gets the personalization for a page (from the base controller) based on Controller and Action. Then the view loops through the widgets and calls renderaction for each of them.
Currently, I have View + "Edit" actions on each view to set the page into edit mode, as I'm duplicating code there must be a better way but I can't see it for the life of me!
How would you implement an action that allows each View to be edited?
public ActionResult Legal()
{
PageModel model = GetPageSetting();
return View("Portal", model.PageSetting.Master.Path, model);
}
[HttpPost]
[Authorize(Roles = "Administrator")]
public ActionResult LegalEdit(EditorModel e)
{
PageModel model = GetPageSetting("Legal", "Home", true);
return View("Portal", model.PageSetting.Master.Path, model);
}
//This is in the base controller
protected PageModel GetPageSetting(string action, string controller, bool isEditing)
{
PersonalizationProcess personalizationProcess = new PersonalizationProcess();
string path = string.Format("~/{0}/{1}", controller, action);
string userName;
bool isAuthenticated;
if (User == null)
{
userName = "TestUser";
isAuthenticated = false;
}
else
{
userName = User.Identity.Name;
isAuthenticated = User.Identity.IsAuthenticated;
}
PageSetting setting = personalizationProcess.GetPageSetting(userName, isAuthenticated, path);
PageModel model = new PageModel();
model.Act = action;
model.Con = controller;
model.IsEditing = isEditing;
model.PageSetting = setting;
return model;