/BlogEngine/DotNetSlave.BusinessLogic/Json/JsonPages.cs
C# | 73 lines | 59 code | 6 blank | 8 comment | 5 complexity | cd03b7150156515266b95caf9f0c86f5 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
- namespace BlogEngine.Core.Json
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- /// <summary>
- /// Json friendly list of pages
- /// </summary>
- public class JsonPages
- {
- /// <summary>
- /// Get list of pages
- /// </summary>
- /// <param name="type">Published or Drafts</param>
- /// <returns>List of pages</returns>
- public static List<JsonPage> GetPages(string type)
- {
- var allPages = new List<Page>();
- var jPages = new List<JsonPage>();
-
- foreach (var p in Page.Pages)
- {
- switch (type)
- {
- case "Published":
- if (p.IsPublished)
- allPages.Add(p);
- break;
- case "Draft":
- if (!p.IsPublished)
- allPages.Add(p);
- break;
- default:
- allPages.Add(p);
- break;
- }
- }
-
- allPages.Sort((x, y) => DateTime.Compare(y.DateCreated, x.DateCreated));
-
- foreach (var x in allPages)
- {
- string prId = "";
- string prTtl = "";
-
- if (x.Parent != Guid.Empty)
- {
- prId = x.Parent.ToString();
- prTtl = Page.Pages.FirstOrDefault(p => p.Id.Equals(x.Parent)).Title;
- }
-
- var jp = new JsonPage
- {
- Id = x.Id,
- ShowInList = x.ShowInList,
- IsPublished = x.IsPublished,
- Title = string.Format("<a href=\"{0}\">{1}</a>", x.RelativeLink, System.Web.HttpContext.Current.Server.HtmlEncode(x.Title)),
- Date = x.DateCreated.ToString("dd MMM yyyy"),
- Time = x.DateCreated.ToString("t"),
- ParentId = prId,
- ParentTitle = prTtl,
- HasChildren = x.HasChildPages,
- CanUserDelete = x.CanUserDelete,
- CanUserEdit = x.CanUserEdit
- };
- jPages.Add(jp);
- }
-
- return jPages;
- }
- }
- }