Esempio n. 1
0
        public PageVariableData(PageTemplateSection pageTemplateSection, PageSection pageSectionOrNull)
        {
            if (pageTemplateSection == null)
            {
                throw new ArgumentNullException("pageTemplateSection");
            }

            this.PageTemplateSection = pageTemplateSection;
            this.PageSection = pageSectionOrNull;
        }
        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;
            }
        }
 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 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 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);
        }
        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);
                }
            }
        }
 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)
         );
 }