示例#1
0
        public IActionResult Index()
        {
            var model = new PostListVM();

            model.Posts = _blogContext.Posts.ToList();
            return(View(model));
        }
示例#2
0
        public ActionResult ViewStaticPosts()
        {
            BlogManager manager  = BlogManagerFactory.Create();
            var         postList = manager.GetAllStaticPosts();

            var postListVM = new PostListVM();

            postListVM.SetPostList(postList);

            return(View(postListVM));
        }
示例#3
0
        //Edit BlogPost
        public void UpdateBlogPost(PostListVM model)
        {
            var post = _context.Posts.Single(o => o.Id == model.Id);

            post.Title = model.Title;
            post.Text  = model.Text;
            post.Link  = model.Link;
            post.Tags  = model.Tags;
            post.Image = model.Image;
            _context.SaveChanges();
        }
示例#4
0
        // GET
        public async Task <IActionResult> Index(int?cid)
        {
            var query = _context.Posts.Include(d => d.Category).Where(d => d.Active == true).AsNoTracking();

            if (cid != null)
            {
                query = query.Where(d => d.CategoryId == cid);
            }

            var list = await query
                       .OrderByDescending(d => d.Id).Skip(0).Take(15).ToListAsync();

            var vm = new PostListVM
            {
                Posts      = list,
                CategoryId = cid
            };

            return(View(vm));
        }
示例#5
0
        public IActionResult Index(PaginationVM pagination, PostFilterVM postFilter)
        {
            if (this.HasAlert)
            {
                this.SetAlertModel();
            }

            var configuration = new MapperConfiguration(cfg =>
                                                        cfg.CreateMap <SalePost, PostVM>().ReverseMap());

            var postsQuery = this.FilterPosts(postFilter, this.salePostService.GetAll().ProjectTo <PostVM>(configuration));

            var paginatedPosts = this.PaginateList <PostVM>(pagination, postsQuery).ToList();

            foreach (var post in paginatedPosts)
            {
                post.Sneaker.PosterImageRelativeLink = FileManager.GetRelativeFilePath(post.Sneaker.PosterImageLink);
                post.Sneaker.OverallRating           = post.Sneaker.Ratings.Any() ? post.Sneaker.Ratings.Average(s => s.Rating.Score) : 0;
            }

            int totalPages = this.GetTotalPages(pagination.PageSize, postsQuery.Count());

            PostListVM postListViewModel = new PostListVM
            {
                Posts          = paginatedPosts,
                NextPage       = pagination.Page < totalPages ? pagination.Page + 1 : pagination.Page,
                PreviousPage   = pagination.Page > 1 ? pagination.Page - 1 : pagination.Page,
                CurrentPage    = pagination.Page,
                TotalPages     = totalPages,
                ShowPagination = totalPages > 1,
            };

            this.LoadListSneakersDropdowns(postFilter);

            return(this.View(postListViewModel));
        }
示例#6
0
 public IActionResult UpdateBlogPost(PostListVM model)
 {
     repository.UpdateBlogPost(model);
     return(RedirectToAction(nameof(HomeController.Index)));
 }