using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using NHibernate; using NHibernate.Linq; using Sleis.Models; using Sleis.Infrastructure; using Sleis.Service; using Sleis.Utility; using Sleis.ViewModels; using Sleis.Validation; using Sleis.Validation.Attribute; namespace Sleis.Controllers { [HandleError] public class PageController : BaseController { public override void Init() { base.Init(); } [HttpGet] public JsonResult Help(string ctrl, string act, string key = null) { ArgumentValidationUtility.ThrowOnEmpty(ctrl, "ctrl"); //ArgumentValidationUtility.ThrowOnEmpty(act, "act"); Log.DebugFormat("Help Referrer:{0} Ctrl:{1} Action:{2} Key:{3}", Request.UrlReferrer, ctrl, key); object model = null; string pageKey = String.IsNullOrEmpty(act) ? ctrl : GetPageContext(ctrl, act); if (pageKey[0] != '/') { pageKey = pageKey.Insert(0, "/"); } //Insert / since all Page_Keys will start with / if (String.IsNullOrEmpty(key)) { model = PageService.GetOrCreatePage(pageKey); } else { model = PageService.CreateDefaultField(pageKey, key); } return Json(model, JsonRequestBehavior.AllowGet); } [HttpGet, AppRoleValidation(AppUserRoleType.AgencyAdmin), Authorize] public ActionResult ManageHelpContent() { List pages = PageService.PageData.GetAll().OrderBy(p=>p.Title).ToList(); List pageSelectItems = new List(); foreach (PageModel p in pages) { pageSelectItems.Add(new SelectListItem { Text = p.Title, Value = p.Id.ToString() }); } return View(new ManageHelpContentViewModel{Pages = pageSelectItems}); } [HttpPost, Authorize,AppRoleValidation(AppUserRoleType.AgencyAdmin)] public ActionResult ManageHelpContent(ManageHelpContentViewModel model) { try { PageService.UpdatePageHelp(model.SelectedPage, model.PageHelpText); PageService.UpdateFieldHelp(model.SelectedField, model.FieldHelpText); return Json(new SimpleMessage("Help Content saved successfully.")); } catch { return Json(new SimpleMessage("Error updating help content.", true)); } return View(); } [HttpGet, Authorize] public ActionResult GetAllPages() { return Json(PageService.PageData.GetAll(), JsonRequestBehavior.AllowGet); } public JsonResult GetAllPageFields(int? pageId) { JsonResult result = new JsonResult(); result.Data = PageService.GetPageFields(pageId.Value).OrderBy(x=>x.Title); return Json(result, JsonRequestBehavior.AllowGet); } public JsonResult GetPage(int pageId) { JsonResult result = new JsonResult(); result.Data = PageService.GetPage(pageId); return Json(result, JsonRequestBehavior.AllowGet); } } }