Example #1
0
        public ViewResult ManagePublishedPosts()
        {
            var posts = blogRepository.GetAllPostsDescending().ToList();
            var model = new AdminManagePublishedPostsModel
            {
                Posts = posts
            };

            return(View(model));
        }
Example #2
0
        private void FillCategories()
        {
            _sortedPublished = new Dictionary <string, List <BlogPostPublished> >();
            var posts = blogRepository.GetAllPostsDescending();
            var cats  = blogRepository.GetAllCategoriesUsed(true);

            foreach (var cat in cats)
            {
                _sortedPublished.Add(cat, posts.Where(p => p.Categories.Contains(cat)).ToList());
            }
        }
Example #3
0
        public void DictGetter_Works()
        {
            IBlogPostRepository repo = Substitute.For <IBlogPostRepository>();
            var posts = Generate10Posts();

            repo.GetAllPostsDescending().Returns(posts);
            repo.GetAllCategoriesUsed()
            .Returns(posts.SelectMany(p => p.Categories).Distinct().ToList());

            CategoriesViewModel model = new CategoriesViewModel(repo);
            var sorted = model.SortedPublished;

            Assert.AreEqual(sorted.Count, 10);
            Assert.AreEqual(sorted["OtherCat"].Count, 9);
            for (int i = 1; i < 10; i++)
            {
                Assert.AreEqual(sorted["Cat" + i].Count, 1);
            }
        }
Example #4
0
        private List <MonthAndYearPostBucket> GetBuckets()
        {
            _bucketsDescending = new List <MonthAndYearPostBucket>();

            var descendingPosts = blogRepository.GetAllPostsDescending();

            List <MonthAndYearPostBucket> buckets = new List <MonthAndYearPostBucket>();
            MonthAndYearPostBucket        bucket  = null;

            foreach (var post in descendingPosts)
            {
                var candidate = new MonthAndYearPostBucket(post);
                if (buckets.Count > 0)
                {
                    var latest = buckets[buckets.Count - 1];
                    if (latest.MonthAndYear == candidate.MonthAndYear)
                    {
                        latest.TryAddPost(post);
                    }
                    else
                    {
                        buckets.Add(candidate);
                    }
                }
                else
                {
                    buckets.Add(candidate);
                }
            }
            // final add
            if (bucket != null)
            {
                buckets.Add(bucket);
            }

            return(buckets);
        }