Exemplo n.º 1
0
        /// <summary>
        /// Gets the post list model.
        /// </summary>
        /// <returns>The model</returns>
        public static PostListModel Get()
        {
            var m = new PostListModel();

            using (var db = new DataContext()) {
                // Get the posts
                m.Posts = db.PostDrafts.
                          Include(p => p.Template).
                          OrderByDescending(p => p.Updated).ToList().
                          Select(p => new PostModel()
                {
                    Id           = p.Id,
                    Title        = p.Title,
                    TemplateName = p.Template.Name,
                    Status       = (!p.LastPublished.HasValue ? PostStatus.UNPUBLISHED : (p.Updated > p.LastPublished ? PostStatus.DRAFT : PostStatus.PUBLISHED)),
                    NewComments  = db.Comments.Where(c => c.ParentId == p.Id && c.InternalStatus == 0).Count(),
                    Created      = p.Created,
                    Updated      = p.Updated
                }).ToList();

                // Get the templates
                m.Templates = db.PostTemplates.
                              OrderBy(t => t.Name).
                              Select(t => new TemplateModel()
                {
                    Id          = t.Id,
                    Name        = t.Name,
                    Description = t.Description,
                    Preview     = t.Preview
                }).ToList();
            }
            return(m);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the post list model.
        /// </summary>
        /// <returns>The model</returns>
        public static PostListModel Get()
        {
            var m = new PostListModel() ;

            using (var db = new DataContext()) {
                // Get the posts
                m.Posts = db.PostDrafts.
                    Include(p => p.Template).
                    OrderByDescending(p => p.Updated).ToList().
                    Select(p => new PostModel() {
                        Id = p.Id,
                        Title = p.Title,
                        TemplateName = p.Template.Name,
                        Status = (!p.LastPublished.HasValue ? PostStatus.UNPUBLISHED : (p.Updated > p.LastPublished ? PostStatus.DRAFT : PostStatus.PUBLISHED)),
                        NewComments = db.Comments.Where(c => c.ParentId == p.Id && c.InternalStatus == 0).Count(),
                        Created = p.Created,
                        Updated = p.Updated
                    }).ToList() ;

                // Get the templates
                m.Templates = db.PostTemplates.
                    OrderBy(t => t.Name).
                    Select(t => new TemplateModel() {
                        Id = t.Id,
                        Name = t.Name,
                        Description = t.Description,
                        Preview = t.Preview
                    }).ToList() ;
            }
            return m ;
        }
Exemplo n.º 3
0
        public static PostListModel GetByBlogId(IApi api, Guid blogId)
        {
            var model = new PostListModel
            {
                Posts = api.Posts.GetAll <PostInfo>(blogId)
                        .Select(p => new PostListItem
                {
                    Id         = p.Id,
                    TypeId     = p.TypeId,
                    Title      = p.Title,
                    CategoryId = p.Category.Id,
                    Category   = p.Category.Title,
                    Published  = p.Published
                }).ToList(),
                PostTypes = api.PostTypes.GetAll()
            };

            // Filter out the currently used post types
            var typesId = model.Posts.Select(p => p.TypeId).Distinct();

            model.CurrentPostTypes = model.PostTypes.Where(t => typesId.Contains(t.Id));

            // Get the currently used categories
            var categoriesId = model.Posts.Select(p => p.CategoryId).Distinct();

            model.CurrentCategories = api.Categories.GetAll(blogId)
                                      .Where(c => categoriesId.Contains(c.Id))
                                      .Select(c => new Taxonomy
            {
                Id    = c.Id,
                Title = c.Title
            });

            // Sort so we show unpublished drafts first
            model.Posts = model.Posts.Where(p => !p.Published.HasValue)
                          .Concat(model.Posts.Where(p => p.Published.HasValue));

            foreach (var post in model.Posts)
            {
                var type = api.PostTypes.GetById(post.TypeId);
                if (type != null)
                {
                    post.TypeName = type.Title;
                }
            }
            return(model);
        }
Exemplo n.º 4
0
        public static PostListModel Get(IApi api, string categorySlug = null)
        {
            var model = new PostListModel();

            model.Categories = api.Categories.Get();
            if (!string.IsNullOrEmpty(categorySlug))
            {
                model.Posts = api.Posts.GetByCategorySlug(categorySlug);
            }
            else
            {
                model.Posts = api.Posts.Get();
            }

            if (!string.IsNullOrEmpty(categorySlug))
            {
                model.Category = model.Categories
                                 .FirstOrDefault(c => c.Slug == categorySlug);
            }
            return(model);
        }
Exemplo n.º 5
0
		/// <summary>
		/// Gets the model for the given parameters.
		/// </summary>
		/// <param name="templateid">The post type id</param>
		/// <returns>The model</returns>
		private static PostListModel Get(Guid templateid) {
			var m = new PostListModel();
			using (var db = new DataContext()) {
				m.ActiveSite = "DEFAULT_SITE";
				var activeSite=HttpContext.Current.Session["activeSite"] as string;
				if (activeSite!=null)
				{
					m.ActiveSite = activeSite;
				}

				m.SiteTrees = db.SiteTrees.OrderBy(s => s.Name).ToList();
				// Get the posts
				var query = db.PostDrafts.Include(p => p.Template);
				if (templateid != Guid.Empty) {
					query = query.Where(p => p.TemplateId == templateid);
					m.ActiveTemplate = templateid;
				}
				m.Posts = query.Where(e=> e.Site == m.ActiveSite).
					OrderByDescending(p => p.Created).ToList().
					Select(p => new PostModel() {
						Id = p.Id,
						Title = p.Title,
						TemplateName = p.Template.Name,
						Status = (!p.LastPublished.HasValue ? PostStatus.UNPUBLISHED : (p.Updated > p.LastPublished ? PostStatus.DRAFT : PostStatus.PUBLISHED)),
						NewComments = db.Comments.Where(c => c.ParentId == p.Id && c.InternalStatus == 0).Count(),
						Created = p.Created,
						Updated = p.Updated
					}).ToList();

				// Get the templates
				m.Templates = db.PostTemplates.
					OrderBy(t => t.Name).
					Select(t => new TemplateModel() {
						Id = t.Id,
						Name = t.Name,
						Description = t.Description,
						Preview = t.Preview
					}).ToList();
			}
			return m;
		}