示例#1
0
        private BlogListModel GetBlogEntries(string user, string date, bool getIsPublishedOnly, int defaultPageSize)
        {
            using (profiler.Step("BlogController.GetBlogEntries"))
            {
                var viewData = new BlogListModel();
                var blogFilter = new BlogFilter();

                var theUser = UserRepository.Load(user);
                if (theUser == null)
                {
                    var family = FamilyRepository.Load(user);
                    if (family == null)
                    {
                        return null;
                    }
                    else
                    {
                        blogFilter.AuthorName = user;
                        blogFilter.LoadBlogBy = LoadBlogBy.Family;
                        viewData.Author.FirstName = family.Description;
                    }
                }
                else
                {
                    blogFilter.AuthorName = theUser.UniqueKey;
                    blogFilter.LoadBlogBy = LoadBlogBy.User;
                    viewData.Author.FirstName = theUser.FirstName;
                }

                viewData.Author.UrlName = user;

                if (!string.IsNullOrEmpty(date))
                    blogFilter.Date = date;
                if (getIsPublishedOnly)
                    blogFilter.IsPublished = true;

                ICacheKey cacheKey = new BlogListCacheKey();
                viewData.BlogTitles = Cache.Get<IDictionary<string, IDictionary<string, IEnumerable<IBlog>>>>(cacheKey.GenerateKey(string.Format("SidebarList:{0}", blogFilter.AuthorName)), () =>
                                GenerateBlogTitles(BlogRepository
                                    .LoadList(blogFilter)
                                    .BlogEntries
                                    .OrderByDescending(b => b.DatePublished)));

                int pageSize = 10;
                if (Int32.TryParse(QueryValue("pageSize"), out pageSize))
                    blogFilter.PageSize = pageSize;
                else
                    blogFilter.PageSize = defaultPageSize;

                int pageIndex = 1;
                if (Int32.TryParse(QueryValue("page"), out pageIndex))
                    blogFilter.PageIndex = pageIndex;
                else
                    blogFilter.PageIndex = 1;

                var model = BlogRepository.LoadList(blogFilter);
                viewData.BlogEntries = model.BlogEntries.OrderByDescending(b => b.DatePublished);
                viewData.PageCount = model.PageCount;
                viewData.PageIndex = model.PageIndex;

                return viewData;
            }
        }
示例#2
0
 public void CacheKey_BlogListCacheKey_GeneratesKey()
 {
     string userKey = "sgwill";
     BlogListCacheKey cacheKey = new BlogListCacheKey();
     Assert.AreEqual(string.Format("{0}:BlogList:{1}", baseKey, userKey), cacheKey.GenerateKey(userKey));
 }