public ActionResult SectionCreate(PageTemplateSection section) { ValidatePageTemplateSectionName(section); if (section.PageTemplateId == default(int)) { return(HttpBadRequest("Page Template id is 0")); } IGstoreDb db = GStoreDb; PageTemplate template = db.PageTemplates.FindById(section.PageTemplateId); if (template == null) { return(HttpNotFound("Page Template not found. Page Template Id: " + section.PageTemplateId)); } if (section.ClientId != template.ClientId) { return(HttpBadRequest("View Model ClientId: " + section.ClientId + " does not match template client id: " + section.ClientId)); } if (ModelState.IsValid) { section = GStoreDb.PageTemplateSections.Add(section); GStoreDb.SaveChanges(); AddUserMessage("Page Template Section Created", "Page Template Section created successfully", UserMessageType.Success); return(RedirectToAction("SectionIndex", new { id = section.PageTemplateId })); } section.PageTemplate = template; this.BreadCrumbsFunc = htmlHelper => this.PageTemplateSectionBreadcrumb(htmlHelper, section, false); return(View(section)); }
public ActionResult SectionDeleteConfirmed(int id) { try { PageTemplateSection target = GStoreDb.PageTemplateSections.FindById(id); if (target == null) { //valueList not found, already deleted? overpost? throw new ApplicationException("Error deleting Page Template Section! Section not found. It may have been deleted by another user. Page Template Section Id: " + id); } bool deleted = GStoreDb.PageTemplateSections.DeleteById(id); GStoreDb.SaveChanges(); if (deleted) { AddUserMessage("Page Template Section Deleted", "Page Template Section [" + id + "] was deleted successfully.", UserMessageType.Success); } else { AddUserMessage("Deleting Page Template Section Failed!", "Deleting Page Template Section Failed. Page Template Section Id: " + id, UserMessageType.Danger); } return(RedirectToAction("SectionIndex", new { id = target.PageTemplateId })); } catch (Exception ex) { throw new ApplicationException("Error deleting Page Template Section. See inner exception for errors. Related child tables may still have data to be deleted. Page Template Section Id: " + id, ex); } }
public ActionResult SectionEdit(PageTemplateSection section) { ValidatePageTemplateSectionName(section); if (section.PageTemplateSectionId == 0) { return(HttpBadRequest("section.PageTemplateSectionId is 0")); } PageTemplateSection sectionToUpdate = GStoreDb.PageTemplateSections.FindById(section.PageTemplateSectionId); if (section == null) { return(HttpNotFound("Page Template Section not found. Page Template Section Id: " + section.PageTemplateSectionId)); } if (section.ClientId != sectionToUpdate.ClientId) { return(HttpBadRequest("View Model ClientId: " + section.ClientId + " does not match template client id: " + section.ClientId)); } if (ModelState.IsValid) { section.UpdateAuditFields(CurrentUserProfileOrThrow); section = GStoreDb.PageTemplateSections.Update(section); GStoreDb.SaveChanges(); AddUserMessage("Page Template Section Updated", "Changes saved successfully to Page Template Section '" + section.Name.ToHtml() + "' [" + section.PageTemplateSectionId + "]", UserMessageType.Success); return(RedirectToAction("SectionIndex", new { id = section.PageTemplateId })); } this.BreadCrumbsFunc = htmlHelper => this.PageTemplateSectionBreadcrumb(htmlHelper, sectionToUpdate, false); return(View(section)); }
public static void SetDefaultsForNew(this PageTemplateSection pageTemplateSection, PageTemplate pageTemplate) { pageTemplateSection.Name = "New Page Template Section"; pageTemplateSection.Order = 100; if (pageTemplate != null) { pageTemplateSection.ClientId = pageTemplate.ClientId; pageTemplateSection.Client = pageTemplate.Client; pageTemplateSection.PageTemplateId = pageTemplate.PageTemplateId; pageTemplateSection.PageTemplate = pageTemplate; pageTemplateSection.Order = pageTemplate.Sections.Count == 0 ? 100 : pageTemplate.Sections.Max(vl => vl.Order) + 10; if (pageTemplate.Sections.Any(pts => pts.Name.ToLower() == pageTemplateSection.Name.ToLower())) { bool nameIsDirty = true; int index = 1; do { index++; pageTemplateSection.Name = "New Page Template Section " + index; nameIsDirty = pageTemplate.Sections.Any(pts => pts.Name.ToLower() == pageTemplateSection.Name.ToLower()); } while (nameIsDirty); } } pageTemplateSection.Description = pageTemplateSection.Name; pageTemplateSection.IsPending = false; pageTemplateSection.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); pageTemplateSection.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); }
public static bool ActivatePageTemplateSection(this SystemAdminBaseController controller, int pageTemplateSectionId) { PageTemplateSection pageTemplateSection = controller.GStoreDb.PageTemplateSections.FindById(pageTemplateSectionId); if (pageTemplateSection == null) { controller.AddUserMessage("Activate Page Template Section Failed!", "Page Template Section not found by id: " + pageTemplateSectionId, AppHtmlHelpers.UserMessageType.Danger); return(false); } if (pageTemplateSection.IsActiveDirect()) { controller.AddUserMessage("Page Template Section is already active.", "Page Template Section is already active. id: " + pageTemplateSectionId, AppHtmlHelpers.UserMessageType.Info); return(false); } pageTemplateSection.IsPending = false; pageTemplateSection.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); pageTemplateSection.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); controller.GStoreDb.PageTemplateSections.Update(pageTemplateSection); controller.GStoreDb.SaveChanges(); controller.AddUserMessage("Activated Page Template Section", "Activated Page Template Section '" + pageTemplateSection.Name.ToHtml() + "' [" + pageTemplateSection.PageTemplateId + "] - Page Template '" + pageTemplateSection.PageTemplate.Name.ToHtml() + "' [" + pageTemplateSection.PageTemplate.PageTemplateId + "]", AppHtmlHelpers.UserMessageType.Info); return(true); }
protected MvcHtmlString PageTemplateSectionBreadcrumb(HtmlHelper htmlHelper, PageTemplateSection pageTemplateSection, bool ShowAsLink = false) { RouteValueDictionary routeData = null; string name = "(unknown)"; bool showLink = false; if (pageTemplateSection != null) { if (pageTemplateSection.PageTemplateSectionId == 0) { name = "New"; } else { showLink = ShowAsLink; routeData = new RouteValueDictionary(new { id = pageTemplateSection.PageTemplateSectionId }); name = "'" + pageTemplateSection.Name + "' [" + pageTemplateSection.PageTemplateSectionId + "]"; } } return(new MvcHtmlString( PageTemplateSectionsBreadcrumb(htmlHelper, pageTemplateSection.PageTemplate, true).ToHtmlString() + " -> " + (showLink ? htmlHelper.ActionLink(name, "SectionDetails", "PageTemplateSysAdmin", routeData, null).ToHtmlString() : name) )); }
protected void ValidatePageTemplateSectionName(PageTemplateSection pageTemplateSection) { if (pageTemplateSection == null) { throw new ArgumentNullException("pageTemplateSection"); } PageTemplateSection conflict = GStoreDb.PageTemplateSections.Where( pt => (pt.ClientId == pageTemplateSection.ClientId) && (pt.Name.ToLower() == pageTemplateSection.Name.ToLower()) && (pt.PageTemplateId == pageTemplateSection.PageTemplateId) && (pt.PageTemplateSectionId != pageTemplateSection.PageTemplateSectionId) ).FirstOrDefault(); if (conflict != null) { this.ModelState.AddModelError("Name", "Page Template Section Name '" + conflict.Name + "' is already in use for Page Template Section '" + conflict.Name.ToHtml() + "' [" + conflict.PageTemplateSectionId + "] for Page Template '" + conflict.PageTemplate.Name.ToHtml() + "' [" + conflict.PageTemplate.PageTemplateId + "] for client '" + conflict.Client.Name.ToHtml() + "' [" + conflict.ClientId + "]. Please choose a new name"); bool nameIsDirty = true; string oldName = pageTemplateSection.Name; int index = 1; while (nameIsDirty) { index++; pageTemplateSection.Name = oldName + " " + index; nameIsDirty = conflict.PageTemplate.Sections.Any(pt => pt.Name.ToLower() == pageTemplateSection.Name.ToLower()); } if (ModelState.ContainsKey("Name")) { ModelState["Name"].Value = new ValueProviderResult(pageTemplateSection.Name, pageTemplateSection.Name, null); } } }
private void UpdateSections( PageTemplateFile fileTemplate, PageTemplateFileInfo fileTemplateDetails, PageTemplate dbPageTemplate, IExecutionContext executionContext ) { // De-dup section names var duplicateSectionName = fileTemplateDetails .Sections .GroupBy(s => s.Name.ToLowerInvariant()) .FirstOrDefault(g => g.Count() > 1); if (duplicateSectionName != null) { throw new PageTemplateRegistrationException($"Dulpicate template section '{ duplicateSectionName.First().Name }' in template { fileTemplate.FullPath }"); } // Deletions var sectionsToDelete = dbPageTemplate .PageTemplateSections .Where(ts => !fileTemplateDetails.Sections.Any(fs => ts.Name.Equals(fs.Name, StringComparison.OrdinalIgnoreCase))) .ToList(); foreach (var sectionToDelete in sectionsToDelete) { _dbContext.PageTemplateSections.Remove(sectionToDelete); } // Updates/Additions foreach (var fileSection in fileTemplateDetails.Sections) { var existing = dbPageTemplate .PageTemplateSections .FirstOrDefault(s => s.Name.Equals(fileSection.Name, StringComparison.OrdinalIgnoreCase)); if (existing == null) { existing = new PageTemplateSection(); existing.PageTemplate = dbPageTemplate; existing.CreateDate = executionContext.ExecutionDate; _dbContext.PageTemplateSections.Add(existing); } // casing might have changed if (existing.Name != fileSection.Name) { existing.Name = fileSection.Name; existing.UpdateDate = executionContext.ExecutionDate; } // this will detach section data but there's no migrating that... if (existing.IsCustomEntitySection != fileSection.IsCustomEntitySection) { existing.IsCustomEntitySection = fileSection.IsCustomEntitySection; existing.UpdateDate = executionContext.ExecutionDate; } } }
/// <summary> /// Returns true if store front and client (parent record) are both active /// </summary> /// <param name="storeFront"></param> /// <returns></returns> public static bool IsActiveBubble(this PageTemplateSection pageTemplateSection) { if (pageTemplateSection == null) { throw new ArgumentNullException("pageTemplateSection"); } return(pageTemplateSection.IsActiveDirect() && pageTemplateSection.PageTemplate.IsActiveBubble()); }
public PageVariableData(PageTemplateSection pageTemplateSection, PageSection pageSectionOrNull) { if (pageTemplateSection == null) { throw new ArgumentNullException("pageTemplateSection"); } this.PageTemplateSection = pageTemplateSection; this.PageSection = pageSectionOrNull; }
public ActionResult SectionDelete(int?id) { if (!id.HasValue) { return(HttpBadRequest("Page Template Section id is null")); } IGstoreDb db = GStoreDb; PageTemplateSection section = db.PageTemplateSections.FindById(id.Value); if (section == null) { return(HttpNotFound("Page Template Section not found by id: " + id)); } this.BreadCrumbsFunc = htmlHelper => this.PageTemplateSectionBreadcrumb(htmlHelper, section, false); return(View(section)); }
protected void SetDefaults(PageTemplateSection pageTemplateSection) { //set defaults this.PageSectionId = null; this.UseDefaultFromTemplate = true; if (pageTemplateSection != null) { this.RawHtml = pageTemplateSection.DefaultRawHtmlValue; this.DefaultRawHtmlValue = pageTemplateSection.DefaultRawHtmlValue; } this.HasPlainText = false; this.HasRawHtml = false; this.HasNothing = false; this.Order = 100; this.Index = 0; this.PlainText = string.Empty; this.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); this.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); this.IsPending = false; }
public ActionResult SectionCreate(int?id) { if (!id.HasValue) { return(HttpBadRequest("Page Template id is null")); } IGstoreDb db = GStoreDb; PageTemplate template = db.PageTemplates.FindById(id.Value); if (template == null) { return(HttpNotFound("Page Template not found. Page Template id: " + id)); } PageTemplateSection model = GStoreDb.PageTemplateSections.Create(); model.SetDefaultsForNew(template); this.BreadCrumbsFunc = htmlHelper => this.PageTemplateSectionBreadcrumb(htmlHelper, model, false); return(View(model)); }
public PageSectionEditViewModel(PageTemplateSection pageTemplateSection, Page page, PageSection pageSection, int index, bool autoSubmit) { if (pageTemplateSection == null) { throw new ArgumentNullException("pageTemplateSection"); } if (page == null) { throw new ArgumentNullException("page", "page must be specified and exist before editing page sections"); } if (index < 1) { throw new ArgumentOutOfRangeException("index", "Index cannot be 0, it starts from 1 and up"); } SetDefaults(pageTemplateSection); this.PageTemplateSectionId = pageTemplateSection.PageTemplateSectionId; this.SectionName = pageTemplateSection.Name; this.DefaultRawHtmlValue = pageTemplateSection.DefaultRawHtmlValue; this.PageId = page.PageId; this.Index = index; this.AutoSubmit = autoSubmit; if (pageSection != null) { this.PageSectionId = pageSection.PageSectionId; this.UseDefaultFromTemplate = pageSection.UseDefaultFromTemplate; this.HasNothing = pageSection.HasNothing; this.HasPlainText = pageSection.HasPlainText; this.HasRawHtml = pageSection.HasRawHtml; this.Order = pageSection.Order; this.PageId = pageSection.PageId; this.PlainText = pageSection.PlainText; this.RawHtml = pageSection.RawHtml; this.StartDateTimeUtc = pageSection.StartDateTimeUtc; this.EndDateTimeUtc = pageSection.EndDateTimeUtc; this.IsPending = pageSection.IsPending; this.UpdateDateTimeUtc = pageSection.UpdateDateTimeUtc; this.UpdatedBy = pageSection.UpdatedBy; } }
public PageVariableEditViewModel(int pageId, PageTemplateSection pageTemplateSection, PageSection pageSectionOrNull) { this.PageId = pageId; if (pageTemplateSection == null) { throw new ArgumentNullException("pageTemplateSection"); } this.PageTemplateSection = pageTemplateSection; if (pageTemplateSection != null) { this.PageTemplateSectionId = pageTemplateSection.PageTemplateSectionId; } this.PageSection = pageSectionOrNull; if (pageSectionOrNull != null) { this.PageSectionId = pageSectionOrNull.PageSectionId; this.StringValue = pageSectionOrNull.StringValue; } this.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); this.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); }