Пример #1
0
        public ActionResult ByCategory(ByAuthorCategoryVM authorCategoryVM)
        {
            ByAuthorCategoryVM categoryVM = new ByAuthorCategoryVM();

            var repo = RepositoryFactory.GetRepository();

            if (Request.IsAuthenticated && User.IsInRole("admin"))
            {
                categoryVM.Posts = repo.GetPostByCategory(authorCategoryVM.CategoryId);
            }
            else
            {
                categoryVM.Posts = repo.GetPublishedPostByCategory(authorCategoryVM.CategoryId);
            }

            categoryVM.StaticPosts          = repo.GetAllStaticPublished();
            categoryVM.Categories           = repo.GetAllCategories();
            categoryVM.Category             = categoryVM.Categories.FirstOrDefault(c => c.CategoryID == authorCategoryVM.CategoryId);
            categoryVM.CategoriesSelectList = (from category in categoryVM.Categories
                                               select new SelectListItem()
            {
                Text = category.CategoryTag,
                Value = category.CategoryID.ToString(),
            }).ToList();

            return(View(categoryVM));
        }
Пример #2
0
        public ActionResult ByAuthor(ByAuthorCategoryVM authorCategoryVM)
        {
            ByAuthorCategoryVM authorVM = new ByAuthorCategoryVM();

            authorVM.AuthorName = authorCategoryVM.AuthorName;

            var repo = RepositoryFactory.GetRepository();

            if (Request.IsAuthenticated && User.IsInRole("admin"))
            {
                authorVM.Posts = repo.GetAllPostByAuthor(authorCategoryVM.AuthorName);
            }
            else
            {
                authorVM.Posts = repo.GetPublishedPostbyAuthor(authorCategoryVM.AuthorName);
            }

            authorVM.StaticPosts       = repo.GetAllStaticPublished();
            authorVM.Categories        = repo.GetAllCategories();
            authorVM.AuthorsSelectList = (from author in repo.GetAllAuthors()
                                          select new SelectListItem()
            {
                Text = author,
                Value = author,
            }).ToList();


            return(View(authorVM));
        }
Пример #3
0
        public ActionResult ByCategory(int id)
        {
            ByAuthorCategoryVM categoryVM = new ByAuthorCategoryVM();

            // all posts in category where id = categoryId

            // are there categories assigned to published posts?
            // when running through debugger, int ID is passed in but GetPublishedPostBtyCategory returns list of 0

            var repo = RepositoryFactory.GetRepository();

            if (Request.IsAuthenticated && User.IsInRole("admin"))
            {
                categoryVM.Posts = repo.GetPostByCategory(id);
            }
            else
            {
                categoryVM.Posts = repo.GetPublishedPostByCategory(id);
            }

            categoryVM.StaticPosts          = repo.GetAllStaticPublished();
            categoryVM.Categories           = repo.GetAllCategories();
            categoryVM.Category             = categoryVM.Categories.FirstOrDefault(c => c.CategoryID == id);
            categoryVM.CategoriesSelectList = (from category in categoryVM.Categories
                                               select new SelectListItem()
            {
                Text = category.CategoryTag,
                Value = category.CategoryID.ToString(),
            }).ToList();

            foreach (var post in categoryVM.Posts)
            {
                repo.SetPostLists(post);
            }

            return(View(categoryVM));
        }