Beispiel #1
0
            /// <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);

                bindingContext.ModelState.Remove("Post.Body");

                model.Post.Body =
                    new HtmlString(bindingContext.ValueProvider.GetUnvalidatedValue("Post.Body").AttemptedValue);

                return(model);
            }
Beispiel #2
0
        /// <summary>
        /// Reverts to the latest published version.
        /// </summary>
        /// <param name="id">The post id</param>
        public static void Revert(Guid id)
        {
            EditModel m = EditModel.GetById(id, false);

            m.Post.IsDraft = true;

            // Saving this baby will overwrite the current draft
            m.SaveAll();

            // Now we just have to "turn back time"
            Post.Execute("UPDATE post SET post_updated = post_last_published WHERE post_id = @0 AND post_draft = 1", null, id);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the model for the post
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static EditModel GetById(Guid id, bool draft = true)
        {
            EditModel m = new EditModel();

            m.Post      = Piranha.Models.Post.GetSingle(id, draft);
            m.Template  = PostTemplate.GetSingle(m.Post.TemplateId);
            m.Permalink = Permalink.GetSingle(m.Post.PermalinkId);
            Category.GetByPostId(m.Post.Id, draft).ForEach(c => m.PostCategories.Add(c.Id));
            m.Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                  new Params()
            {
                OrderBy = "category_name"
            }), "Id", "Name", m.PostCategories);
            m.GetRelated();

            return(m);
        }
Beispiel #4
0
        public ActionResult Edit(bool draft, EditModel m)
        {
            if (ModelState.IsValid) {
                if (m.SaveAll(draft)) {
                    ModelState.Clear() ;
                    if (!draft)
                        ViewBag.Message = "Din artikel har publicerats." ;
                    else ViewBag.Message = "Din artikel har sparats." ;
                } else ViewBag.Message = "Artikeln kunde inte sparas." ;
            }
            m.Refresh() ;

            if (m.Post.IsNew)
                ViewBag.Title = "Lägg till " + m.Template.Name.Singular.ToLower() ;
            else ViewBag.Title = "Ändra " + m.Template.Name.Singular.ToLower() ;

            return View("Edit", m) ;
        }
Beispiel #5
0
        public ActionResult Edit(bool draft, EditModel m)
        {
            if (ModelState.IsValid) {
                if (m.SaveAll(draft)) {
                    ModelState.Clear() ;
                    if (!draft)
                        SuccessMessage(Piranha.Resources.Post.MessagePublished) ;
                    else SuccessMessage(Piranha.Resources.Post.MessageSaved) ;
                } else ErrorMessage(Piranha.Resources.Post.MessageNotSaved) ;
            }
            m.Refresh() ;

            if (m.Post.IsNew)
                ViewBag.Title = Piranha.Resources.Post.EditTitleNew + m.Template.Name.ToLower() ;
            else ViewBag.Title = Piranha.Resources.Post.EditTitleExisting ;

            return View("Edit", m) ;
        }
Beispiel #6
0
            /// <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);

                bindingContext.ModelState.Remove("Post.Body");

                model.Post.Body =
                    new HtmlString(bindingContext.ValueProvider.GetUnvalidatedValue("Post.Body").AttemptedValue);

                // Allow HtmlString extensions
                model.Extensions.Each((i, m) => {
                    if (m.Body is HtmlString)
                    {
                        bindingContext.ModelState.Remove("Extensions[" + i + "].Body");
                        m.Body = ExtensionManager.Current.CreateInstance(m.Type,
                                                                         bindingContext.ValueProvider.GetUnvalidatedValue("Extensions[" + i + "].Body").AttemptedValue);
                    }
                });
                return(model);
            }
Beispiel #7
0
        /// <summary>
        /// Creates a new post from the given template and return it
        /// as a 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.Permalink = new Permalink()
            {
                Id          = Guid.NewGuid(),
                Type        = Permalink.PermalinkType.POST,
                NamespaceId = Config.DefaultNamespaceId
            };
            m.Post = new Piranha.Models.Post()
            {
                Id          = Guid.NewGuid(),
                TemplateId  = templateId,
                PermalinkId = m.Permalink.Id
            };
            m.Template = PostTemplate.GetSingle(templateId);
            m.GetRelated();

            return(m);
        }
Beispiel #8
0
        public ActionResult Edit(bool draft, EditModel m)
        {
            if (ModelState.IsValid) {
                if (m.SaveAll(draft)) {
                    ModelState.Clear() ;
                    if (!draft)
                        SuccessMessage(Piranha.Resources.Post.MessagePublished) ;
                    else SuccessMessage(Piranha.Resources.Post.MessageSaved) ;
                } else ErrorMessage(Piranha.Resources.Post.MessageNotSaved) ;
            }
            m.Refresh() ;

            // Executes the post edit loaded hook, if registered
            if (WebPages.Hooks.Manager.PostEditModelLoaded != null)
                WebPages.Hooks.Manager.PostEditModelLoaded(this, WebPages.Manager.GetActiveMenuItem(), m) ;

            if (m.Post.IsNew)
                ViewBag.Title = Piranha.Resources.Post.EditTitleNew + m.Template.Name.ToLower() ;
            else ViewBag.Title = Piranha.Resources.Post.EditTitleExisting ;

            return View(@"~/Areas/Manager/Views/Post/Edit.cshtml", m) ;
        }
Beispiel #9
0
		/// <summary>
		/// Gets the model for the post
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public static EditModel GetById(Guid id, bool draft = true) {
			EditModel m = new EditModel() ;
			m.Post = Piranha.Models.Post.GetSingle(id, draft) ;
			m.Template = PostTemplate.GetSingle(m.Post.TemplateId) ;
			m.Permalink = Permalink.GetSingle(m.Post.PermalinkId) ;
			Category.GetByPostId(m.Post.Id, draft).ForEach(c => m.PostCategories.Add(c.Id)) ;
			m.Categories = new MultiSelectList(Category.GetFields("category_id, category_name", 
				new Params() { OrderBy = "category_name" }), "Id", "Name", m.PostCategories) ;
			m.GetRelated() ;

			return m ;
		}
Beispiel #10
0
		/// <summary>
		/// Creates a new post from the given template and return it 
		/// as a 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.Permalink = new Permalink() {
				Id = Guid.NewGuid(),
				Type = Permalink.PermalinkType.POST,
				NamespaceId = Config.DefaultNamespaceId
			} ;
			m.Post = new Piranha.Models.Post() {
				Id = Guid.NewGuid(),
				TemplateId = templateId,
				PermalinkId = m.Permalink.Id
			} ;
			m.Template = PostTemplate.GetSingle(templateId) ;
			m.GetRelated() ;

			return m ;
		}
Beispiel #11
0
		public ActionResult Edit(bool draft, EditModel m) {
			if (ModelState.IsValid) {
				try {
					if (m.SaveAll(draft)) {
						ModelState.Clear() ;
						if (!draft) {
							if (m.Post.Published == m.Post.LastPublished)
								SuccessMessage(Piranha.Resources.Post.MessagePublished, true) ;
							else SuccessMessage(Piranha.Resources.Post.MessageUpdated, true) ;
						} else SuccessMessage(Piranha.Resources.Post.MessageSaved, true) ;

						return RedirectToAction("edit", new { id = m.Post.Id, returl = ViewBag.ReturnUrl }) ;
					} else ErrorMessage(Piranha.Resources.Post.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(m.Post.Title) == m.Permalink.Name)
						ModelState.Remove("Permalink.Name") ;
				} catch (Exception e) {
					ErrorMessage(e.ToString()) ;
				}
			}
			m.Refresh() ;

			// Executes the post edit loaded hook, if registered
			if (WebPages.Hooks.Manager.PostEditModelLoaded != null)
				WebPages.Hooks.Manager.PostEditModelLoaded(this, WebPages.Manager.GetActiveMenuItem(), m) ;

			if (m.Post.IsNew)
				ViewBag.Title = Piranha.Resources.Post.EditTitleNew + m.Template.Name.ToLower() ;
			else ViewBag.Title = Piranha.Resources.Post.EditTitleExisting ;

			return View(@"~/Areas/Manager/Views/Post/Edit.cshtml", m) ;
		}
Beispiel #12
0
        /// <summary>
        /// Creates a new post from the given template and return it 
        /// as a 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.Permalink = new Permalink() {
                Id = Guid.NewGuid(),
                Type = Permalink.PermalinkType.POST,
                NamespaceId = Config.DefaultNamespaceId
            } ;
            m.Post = new Piranha.Models.Post() {
                Id = Guid.NewGuid(),
                TemplateId = templateId,
                PermalinkId = m.Permalink.Id
            } ;
            m.Template = PostTemplate.GetSingle(templateId) ;
            m.Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                new Params() { OrderBy = "category_name" }), "Id", "Name") ;
            m.GetRelated() ;

            return m ;
        }