public static List<JsonBlog> GetBlogs(int page, int pageSize)
{
pageSize = Math.Max(pageSize, 1);
var cntTo = page * pageSize;
var cntFrom = cntTo - pageSize;
var cnt = 0;
// putting blogs into its own list so we can sort it without
// modifying the original collection.
var blogs = new List<Blog>(Blog.Blogs);
// sort so primary blog comes first, followed by other blogs
// in alphabetical order.
blogs.Sort((x, y) =>
{
if (x.IsPrimary && !y.IsPrimary)
return -1;
else if (!x.IsPrimary && y.IsPrimary)
return 1;
return x.Name.CompareTo(y.Name);
});
var jsonBlogs = new List<JsonBlog>();
// convert each blog into smaller Json friendly object
foreach (var x in blogs)
{
cnt++;
if (cnt <= cntFrom || cnt > cntTo)
{
continue;
}
jsonBlogs.Add(CreateJsonBlog(x));
}
currentPage = page;
blogCnt = cnt;
return jsonBlogs;
}