public ActionResult ShowAllBlogPost(BlogPostAllVM model)
        {
            var categoryId = model.SelectedCategoryId;
            var hashtagId = model.SelectedHashtagId;
            var categoryOps = OperationsFactory.CreateCategoryOps();
            var hashtagOps = OperationsFactory.CreateHashtagOps();
            var ops = OperationsFactory.CreateBlogPostOps();
            if (categoryId != 0)
            {
                model.BlogPosts = ops.ListAllBlogsInCategoryByCategoryId(categoryId).FindAll(x => x.Status.StatusID == 2)
                    .FindAll(x => x.DateOfPost <= DateTime.Today)
                    .OrderByDescending(x => x.DateOfPost)
                    .ToList();
                var firstOrDefault = categoryOps.ListAllCategories().FirstOrDefault(x => x.CategoryID == categoryId);
                if (firstOrDefault != null)
                    model.SelectedCategoryName =
                        firstOrDefault.CategoryType;
            }
            else
            {
                model.BlogPosts = ops.ListAllBlogsByHashTag(hashtagId).FindAll(x => x.Status.StatusID == 2)
                    .FindAll(x => x.DateOfPost <= DateTime.Today)
                    .OrderByDescending(x => x.DateOfPost)
                    .ToList();
                var firstOrDefault = hashtagOps.ListAllHashtags().FirstOrDefault(x => x.HashtagID == hashtagId);
                if (firstOrDefault != null)
                    model.SelectedHashtagName =
                        firstOrDefault.HashtagType;
            }

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var ops = OperationsFactory.CreateBlogPostOps();
            BlogPostAllVM postsVM = new BlogPostAllVM()
            {
                BlogPosts = ops.GetAllBlogPosts().FindAll(x=>x.Status.StatusID == 2).FindAll(x=>x.DateOfPost <= DateTime.Today).OrderByDescending(x=>x.DateOfPost).Take(5).ToList(),
            };

            return View(postsVM);
        }
        public ActionResult ShowAllBlogPost()
        {
            var model = new BlogPostAllVM();

            var categoryOps = OperationsFactory.CreateCategoryOps();
            var hashtagOps = OperationsFactory.CreateHashtagOps();
            var categoriesList = categoryOps.ListAllCategories();
            var hashtagsList = hashtagOps.ListAllHashtags();
            var ops = OperationsFactory.CreateBlogPostOps();

            model.BlogPosts =
                ops.GetAllBlogPosts()
                    .FindAll(x => x.Status.StatusID == 2)
                    .FindAll(x => x.DateOfPost <= DateTime.Today)
                    .OrderByDescending(x => x.DateOfPost)
                    .ToList();
            model.GenerateCategoriesList(categoriesList);
            model.GenerateHashtagsList(hashtagsList);

            return View(model);
        }