Exemple #1
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 = new Guid("8FF4A4B4-9B6C-4176-AAA2-DB031D75AC03")
            };
            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);
        }
Exemple #2
0
		/// <summary>
		/// Gets the model for the template specified by the given id.
		/// </summary>
		/// <param name="id">The template id</param>
		/// <returns>The model</returns>
		public static PostEditModel GetById(Guid id) {
			PostEditModel m = new PostEditModel();
			m.Template = PostTemplate.GetSingle(id);
			if (m.Template.Properties == null)
				m.Template.Properties = new List<string>();
			if (m.Template.PermalinkId != Guid.Empty)
				m.Permalink = Permalink.GetSingle(m.Template.PermalinkId);
			else m.Template.PermalinkId = m.Permalink.Id;

			return m;
		}
Exemple #3
0
        /// <summary>
        /// Gets the model for the template specified by the given id.
        /// </summary>
        /// <param name="id">The template id</param>
        /// <returns>The model</returns>
        public static PostEditModel GetById(Guid id)
        {
            PostEditModel m = new PostEditModel();

            m.Template = PostTemplate.GetSingle(id);
            if (m.Template.Properties == null)
            {
                m.Template.Properties = new List <string>();
            }

            return(m);
        }
Exemple #4
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);
        }
Exemple #5
0
 /// <summary>
 /// Refreshes the current model.
 /// </summary>
 public void Refresh()
 {
     if (Post != null)
     {
         if (!Post.IsNew)
         {
             Post      = Piranha.Models.Post.GetSingle(Post.Id, true);
             Permalink = Permalink.GetSingle(Post.PermalinkId);
             Category.GetByPostId(Post.Id).ForEach(c => PostCategories.Add(c.Id));
             Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                 new Params()
             {
                 OrderBy = "category_name"
             }), "Id", "Name", PostCategories);
         }
         Template = PostTemplate.GetSingle(Post.TemplateId);
         GetRelated();
     }
 }
Exemple #6
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);
        }