public ActionResult PageDelete(long?id) { if (!Permission.CanDeletePages) { return(new HttpUnauthorizedResult("User does not have permission to delete Pages")); } Context context = new Context(); Cydon.Data.CySys.Page page = context.Pages.FirstOrDefault(p => p.PageID == id); if (page == null) { return(HttpNotFound("Could not find Page")); } context.Pages.Remove(page); context.SaveChanges(); return(RedirectToAction("CountryIndex", new { countryid = CountryID })); }
public ActionResult PageAdd(FormCollection collection) { if (!Permission.CanAddPages) { return(new HttpUnauthorizedResult("User does not have permission to Add pages")); } Dictionary <string, string> errors = new Dictionary <string, string>(); if (!collection.AllKeys.Contains("Name")) { errors.Add("Name", "Name is a required field"); } if (errors.Any()) { return(Json(new { success = false, errors })); } Cydon.Data.CySys.Page page = new Cydon.Data.CySys.Page(); page.Name = collection["Name"]; page.CountryID = CountryID.Value; Context context = new Context(); context.Pages.Add(page); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { return(ModalSaveFailedResult(ex)); } return(Json(new { success = true })); }
public ActionResult PageDetails(long?id) { if (!Permission.CanAddPages) { return(new HttpUnauthorizedResult("User does not have permission to edit Pages")); } Context context = new Context(); Cydon.Data.CySys.Page page = context.Pages.FirstOrDefault(p => p.PageID == id); if (page == null) { return(HttpNotFound("Could not find Page")); } #region Build Editor Parts Stream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); HtmlTextWriter htmlWriter = new HtmlTextWriter(writer); foreach (PageElement content in page.PageElements.OrderBy(pe => pe.DisplayOrder)) { Div elementDiv = new Div() { Class = { "p-1", "mb-1", "bg-light", "rounded" }, PageElement = content }; if (!content.CountryRolePageElements.Any(crpe => crpe.CanView && crpe.CountryRole.CountryRoleUsers.Any(cru => cru.UserID == UserID))) { elementDiv.Parts.Add(new Header() { HeaderType = Header.HeaderTypes.H6, Text = "You don't have permission to view this Page Element" }); elementDiv.Render(htmlWriter); continue; } XElement xElement = XElement.Parse(content.ElementXML); string typeName = xElement.Attribute("type")?.Value; if (string.IsNullOrEmpty(typeName)) { continue; } Type type = Type.GetType(typeName); if (!typeof(PageContentViewPart).IsAssignableFrom(type)) { continue; } bool editable = content.CountryRolePageElements.Any(crpe => crpe.CanEdit && crpe.CountryRole.CountryRoleUsers.Any(cru => cru.UserID == UserID)); if (editable) { Span rightAligned = new Span() { Class = { "float-right" } }; Button moveUp = new Button() { Class = { "btn", "btn-outline-primary" }, Type = "button", OnClick = "movePageElementUp($(this));", ViewPartsBeforeText = new List <ViewPart>() { new Span() { Class = { "fas", "fa-chevron-up" } } } }; Button moveDown = new Button() { Class = { "btn", "btn-outline-primary" }, Type = "button", OnClick = "movePageElementDown($(this));", ViewPartsBeforeText = new List <ViewPart>() { new Span() { Class = { "fas", "fa-chevron-down" } } } }; Button remove = new Button() { Class = { "btn", "btn-danger" }, Type = "button", OnClick = "deletePageElement($(this));", ViewPartsBeforeText = new List <ViewPart>() { new Span() { Class = { "fas", "fa-trash" } } } }; rightAligned.Parts.Add(moveUp); rightAligned.Parts.Add(moveDown); rightAligned.Parts.Add(remove); elementDiv.Parts.Add(rightAligned); } Form form = new Form() { Id = $"PageElement-{content.PageElementID}", Action = "." }; form.Parts.Add(new Div() { Class = { "genericError", "bg-danger" } }); PageContentViewPart pageContentViewPart = (PageContentViewPart)Activator.CreateInstance(type); pageContentViewPart.PageElement = content; pageContentViewPart.EditorMode = true; pageContentViewPart.ReadOnly = !editable; pageContentViewPart.ReadFromXML(xElement); form.Parts.Add(pageContentViewPart); form.Parts.Add(new Hidden() { Id = "PageElementID", Value = content.PageElementID.ToString() }); form.Parts.Add(new Hidden() { Id = "CountryID", Value = content.Page.CountryID.ToString() }); form.Parts.Add(new Hidden() { Id = "ElementType", Value = type.Name }); if (editable) { form.Parts.Add(new Button() { Type = "button", Class = { "btn", "btn-primary" }, ViewPartsBeforeText = { new Span() { Class ={ "fas", "fa-save" } } }, Text = " Save", OnClick = "savePageElement($(this));" }); form.Parts.Add(new Button() { Type = "button", Class = { "btn", "btn-primary", "ml-1" }, ViewPartsBeforeText = { new Span() { Class ={ "fas", "fa-user-edit" } } }, Text = " Permissions", OnClick = "$('#ManagePageElementPermissions').find('input[name=\"PageElementID\"]').val('" + content.PageElementID + "');$('#ManagePageElementPermissions').modal('show');" }); } elementDiv.Parts.Add(form); elementDiv.Render(htmlWriter); } htmlWriter.Flush(); stream.Position = 0; ViewData["Content"] = new StreamReader(stream).ReadToEnd(); #endregion #region Get Add-able Parts Type addablePartType = typeof(PageContentViewPart); List <string> addableParts = new List <string>(); foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(t => t != addablePartType && addablePartType.IsAssignableFrom(t))) { addableParts.Add(type.Name); } ViewData["AddableParts"] = addableParts; #endregion htmlWriter.Close(); stream.Close(); return(View(page)); }
// GET: Country public ActionResult Index(string country, string page, long?id) { if (string.IsNullOrEmpty(country)) { country = "Cydon"; } if (string.IsNullOrEmpty(page)) { page = "Index"; } Context context = new Context(); Country selectedCountry = context.Countries.FirstOrDefault(c => c.Name == country); if (selectedCountry == null) { return(HttpNotFound("Country not found")); } Cydon.Data.CySys.Page selectedPage = selectedCountry.Pages.FirstOrDefault(p => p.Name == page); if (selectedPage == null) { return(HttpNotFound("Page not found")); } MemoryStream stream = new MemoryStream(); HtmlTextWriter textWriter = new HtmlTextWriter(new StreamWriter(stream)); foreach (PageElement pageElement in selectedPage.PageElements.OrderBy(pe => pe.DisplayOrder)) { if (pageElement.ForAuthenticatedOnly && UserID == null) { continue; } XDocument elementXML = XDocument.Parse(pageElement.ElementXML); Type elementType = Type.GetType(elementXML.Root.Attribute("type").Value); if (!typeof(PageContentViewPart).IsAssignableFrom(elementType)) { continue; } PageContentViewPart viewPart = (PageContentViewPart)Activator.CreateInstance(elementType); viewPart.PageElement = pageElement; viewPart.ReadFromXML(elementXML.Root); viewPart.Render(textWriter); } StreamReader reader = new StreamReader(stream); textWriter.Flush(); stream.Position = 0; ViewData["Content"] = reader.ReadToEnd(); reader.Close(); textWriter.Close(); if (Request.QueryString.AllKeys.Contains("signoutReason")) { ViewData["signoutSuccessful"] = true; } return(View()); }