public ActionResult Edit(bool draft, EditModel pm) { if (ModelState.IsValid) { try { if (pm.SaveAll(draft)) { ModelState.Clear() ; if (!draft) SuccessMessage(Piranha.Resources.Page.MessagePublished) ; else SuccessMessage(Piranha.Resources.Page.MessageSaved) ; } else ErrorMessage(Piranha.Resources.Page.MessageNotSaved) ; } catch (DuplicatePermalinkException e) { // Manually set the duplicate error. ModelState.AddModelError("Permalink", @Piranha.Resources.Global.PermalinkDuplicate) ; // If this is the default permalink, remove the model state so it will be shown. if (Permalink.Generate(pm.Page.Title) == pm.Permalink.Name) ModelState.Remove("Permalink.Name") ; } catch (Exception e) { ErrorMessage(e.ToString()) ; } } pm.Refresh(); if (pm.Page.IsNew) ViewBag.Title = Piranha.Resources.Page.EditTitleNew + pm.Template.Name.ToLower() ; else ViewBag.Title = Piranha.Resources.Page.EditTitleExisting ; return View("Edit", pm) ; }
/// <summary> /// Reverts to the latest published version. /// </summary> /// <param name="id">The page id</param> public static void Revert(Guid id) { EditModel m = EditModel.GetById(id, false); m.Page.IsDraft = true; // Saving this baby will overwrite the current draft m.SaveAll(); // Now we just have to "turn back time" Page.Execute("UPDATE page SET page_updated = page_last_published WHERE page_id = @0 AND page_draft = 1", null, id); }
/// <summary> /// Creates a new page from the given template and returns it /// as an edit model. /// </summary> /// <param name="templateId">The template id</param> /// <returns>The edit model</returns> public static EditModel CreateByTemplate(Guid templateId) { EditModel m = new EditModel(); m.Page = new Piranha.Models.Page() { Id = Guid.NewGuid(), TemplateId = templateId }; m.GetRelated(); return(m); }
/// <summary> /// Extend the default binder so that html strings can be fetched from the post. /// </summary> /// <param name="controllerContext">Controller context</param> /// <param name="bindingContext">Binding context</param> /// <returns>The page edit model</returns> public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { EditModel model = (EditModel)base.BindModel(controllerContext, bindingContext); model.Regions.Each <Region>((i, m) => { if (m.Body is HtmlString) { bindingContext.ModelState.Remove("Regions[" + i + "].Body"); m.Body = App.Instance.ExtensionManager.CreateInstance(m.Type, bindingContext.ValueProvider.GetUnvalidatedValue("Regions[" + i + "].Body").AttemptedValue); } }); return(model); }
/// <summary> /// Creates a new page from the given template and position and returns it /// as an edit model. /// </summary> /// <param name="templateId">The template id</param> /// <param name="parentId">The parent id</param> /// <param name="seqno">The position sequence number</param> /// <returns>The edit model</returns> public static EditModel CreateByTemplateAndPosition(Guid templateId, Guid parentId, int seqno) { EditModel m = new EditModel(); m.Page = new Piranha.Models.Page() { Id = Guid.NewGuid(), TemplateId = templateId, ParentId = parentId, Seqno = seqno }; m.GetRelated(); return(m); }
/// <summary> /// Gets the model for the page specified by the given id. /// </summary> /// <param name="id">The page id</param> /// <param name="draft">Weather to get the draft or not.</param> /// <returns>The model</returns> public static EditModel GetById(Guid id, bool draft = true) { EditModel m = new EditModel(); m.Page = Piranha.Models.Page.GetSingle(id, draft); if (m.Page == null) { m.Page = Piranha.Models.Page.GetSingle(id); } if (m.Page != null) { m.GetRelated(); } else { throw new ArgumentException("Could not find page with id {" + id.ToString() + "}"); } return(m); }
/// <summary> /// Gets the model for the page specified by the given id. /// </summary> /// <param name="id">The page id</param> /// <param name="draft">Whether to get the draft or not.</param> /// <returns>The model</returns> public static EditModel GetById(Guid id, bool draft = true) { EditModel m = new EditModel(); m.Page = Piranha.Models.Page.GetSingle(id, draft); if (m.Page == null) { m.Page = Piranha.Models.Page.GetSingle(id); } if (m.Page != null) { m.GetRelated(); m.CanDelete = Page.GetScalar("SELECT count(*) FROM page WHERE page_parent_id=@0", id) == 0; } else { throw new ArgumentException("Could not find page with id {" + id.ToString() + "}"); } return(m); }
public ActionResult Edit(bool draft, EditModel pm) { if (ModelState.IsValid) { try { if (pm.SaveAll(draft)) { ModelState.Clear() ; if (!draft) SuccessMessage(Piranha.Resources.Page.MessagePublished) ; else SuccessMessage(Piranha.Resources.Page.MessageSaved) ; } else ErrorMessage(Piranha.Resources.Page.MessageNotSaved) ; } catch (Exception e) { ErrorMessage(e.ToString()) ; } } pm.Refresh(); if (pm.Page.IsNew) ViewBag.Title = Piranha.Resources.Page.EditTitleNew + pm.Template.Name.ToLower() ; else ViewBag.Title = Piranha.Resources.Page.EditTitleExisting ; return View("Edit", pm) ; }
public static EditModel CreateByOriginalAndPosition(Guid originalId, Guid parentId, int seqno, Guid siteTreeId, string siteTree) { var m = new EditModel(); var p = Page.GetSingle(originalId, true); m.Page = new Piranha.Models.Page() { Id = Guid.NewGuid(), Title = p.Title, NavigationTitle = p.NavigationTitle, TemplateId = p.TemplateId, OriginalId = originalId, SiteTreeId = siteTreeId, SiteTreeInternalId = siteTree, ParentId = parentId, Seqno = seqno, PageController = p.PageController, PageRedirect = p.PageRedirect }; m.GetRelated(); return(m); }
public static EditModel CreateByOriginalAndPosition(Guid originalId, Guid parentId, int seqno, Guid siteTreeId, string siteTree) { var m = new EditModel(); var p = Page.GetSingle(originalId, true); m.Page = new Piranha.Models.Page() { Id = Guid.NewGuid(), Title = p.Title, NavigationTitle = p.NavigationTitle, TemplateId = p.TemplateId, OriginalId = originalId, SiteTreeId = siteTreeId, SiteTreeInternalId = siteTree, ParentId = parentId, Seqno = seqno, PageController = p.PageController, PageRedirect = p.PageRedirect }; m.GetRelated(); return m; }
/// <summary> /// Creates a new page from the given template and position and returns it /// as an edit model. /// </summary> /// <param name="templateId">The template id</param> /// <param name="parentId">The parent id</param> /// <param name="seqno">The position sequence number</param> /// <param name="siteTreeId">The id of the site tree</param> /// <param name="siteTree">The internal id of the site tree</param> /// <returns>The edit model</returns> public static EditModel CreateByTemplateAndPosition(Guid templateId, Guid parentId, int seqno, Guid siteTreeId, string siteTree) { EditModel m = new EditModel(); m.Page = new Piranha.Models.Page() { Id = Guid.NewGuid(), TemplateId = templateId, SiteTreeId = siteTreeId, SiteTreeInternalId = siteTree, ParentId = parentId, Seqno = seqno }; m.GetRelated(); return m; }
/// <summary> /// Gets the model for the page specified by the given id. /// </summary> /// <param name="id">The page id</param> /// <param name="draft">Whether to get the draft or not.</param> /// <returns>The model</returns> public static EditModel GetById(Guid id, bool draft = true) { EditModel m = new EditModel(); m.Page = Piranha.Models.Page.GetSingle(id, draft); if (m.Page == null) m.Page = Piranha.Models.Page.GetSingle(id); if (m.Page != null) { m.GetRelated(); m.CanDelete = Page.GetScalar("SELECT count(*) FROM page WHERE page_parent_id=@0", id) == 0; } else throw new ArgumentException("Could not find page with id {" + id.ToString() + "}"); return m; }
public static EditModel CreateByTemplate(Guid templateId) { EditModel m = new EditModel() ; m.Page = new Piranha.Models.Page() { Id = Guid.NewGuid(), TemplateId = templateId, SiteTreeId = Config.SiteTreeId } ; m.GetRelated() ; return m ; }
/// <summary> /// Gets the model for the page specified by the given id. /// </summary> /// <param name="id">The page id</param> /// <param name="draft">Weather to get the draft or not.</param> /// <returns>The model</returns> public static EditModel GetById(Guid id, bool draft = true) { EditModel m = new EditModel() ; m.Page = Piranha.Models.Page.GetSingle(id, draft) ; if (m.Page == null) m.Page = Piranha.Models.Page.GetSingle(id) ; if (m.Page != null) { m.GetRelated() ; } else throw new ArgumentException("Could not find page with id {" + id.ToString() + "}") ; return m ; }
public ActionResult Edit(bool draft, EditModel pm) { if (ModelState.IsValid) { try { // Executes the page edit before save hook, if registered if (WebPages.Hooks.Manager.PageEditModelBeforeSave != null) WebPages.Hooks.Manager.PageEditModelBeforeSave(this, WebPages.Manager.GetActiveMenuItem(), pm) ; if (pm.SaveAll(draft)) { // Executes the page edit after save hook, if registered if (WebPages.Hooks.Manager.PageEditModelAfterSave != null) WebPages.Hooks.Manager.PageEditModelAfterSave(this, WebPages.Manager.GetActiveMenuItem(), pm) ; ModelState.Clear() ; if (!draft) { if (pm.Page.Published == pm.Page.LastPublished) SuccessMessage(Piranha.Resources.Page.MessagePublished) ; else SuccessMessage(Piranha.Resources.Page.MessageUpdated) ; } else SuccessMessage(Piranha.Resources.Page.MessageSaved) ; } else ErrorMessage(Piranha.Resources.Page.MessageNotSaved) ; } catch (DuplicatePermalinkException) { // Manually set the duplicate error. ModelState.AddModelError("Permalink", @Piranha.Resources.Global.PermalinkDuplicate) ; // If this is the default permalink, remove the model state so it will be shown. if (Permalink.Generate(pm.Page.Title) == pm.Permalink.Name) ModelState.Remove("Permalink.Name") ; } catch (Exception e) { ErrorMessage(e.ToString()) ; } } pm.Refresh(); // Executes the page list loaded hook, if registered if (WebPages.Hooks.Manager.PageEditModelLoaded != null) WebPages.Hooks.Manager.PageEditModelLoaded(this, WebPages.Manager.GetActiveMenuItem(), pm) ; if (!pm.IsSite) { if (pm.Page.IsNew) ViewBag.Title = Piranha.Resources.Page.EditTitleNew + pm.Template.Name.ToLower() ; else ViewBag.Title = Piranha.Resources.Page.EditTitleExisting ; } else ViewBag.Title = Piranha.Resources.Global.Edit + " " + pm.SiteTree.Name.ToLower() ; if (pm.Page.OriginalId != Guid.Empty) return View(@"~/Areas/Manager/Views/Page/EditCopy.cshtml", pm) ; return View(@"~/Areas/Manager/Views/Page/Edit.cshtml", pm) ; }