public async Task <BaseReponse <ModelListResult <BlogCommentViewModel> > > GetAllPaging(BlogCommentRequest request)
        {
            var query = await _blogCommentRepository.FindAll();

            if (request.BlogId > 0)
            {
                query = query.Where(x => x.BlogId == request.BlogId);
            }

            int totalRow = query.Count();

            query = query.OrderByDescending(x => x.DateCreated)
                    .Skip(request.PageIndex * request.PageSize)
                    .Take(request.PageSize);

            var items = new BlogCommentViewModel().Map(query).ToList();

            return(new BaseReponse <ModelListResult <BlogCommentViewModel> >
            {
                Data = new ModelListResult <BlogCommentViewModel>()
                {
                    Items = items,
                    Message = Message.Success,
                    RowCount = totalRow,
                    PageSize = request.PageSize,
                    PageIndex = request.PageIndex
                },
                Message = Message.Success,
                Status = (int)QueryStatus.Success
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(int id)
        {
            var model = new BlogDetailViewModel();

            model.Blog = await _blogService.GetById(id);

            model.Blog.CountComment = (await _blogComment.FindAll()).Count(x => x.BlogId == id);
            model.Categories        = await _blogCategoryService.GetAll();

            model.PopularPosts = (from k in (await _blogService.GetAll()).OrderByDescending(x => x.DateModified).ToList()
                                  select new BlogViewModel
            {
                Image = k.Image,
                Id = k.Id,
                CountComment = 4,
                DateModified = k.DateModified,
                Description = k.Description,
                SeoAlias = k.SeoAlias
            }).Take(5);
            model.ReLateBlogs = (from b in (await _blogService.GetAll()).Where(x => x.BlogCategoryId == model.Blog.BlogCategoryId && x.Id != id).ToList()
                                 select new BlogViewModel
            {
                Image = b.Image,
                Id = b.Id,
                CountComment = 0,
                //  CountComment =(await _blogComment.FindAll(y => y.BlogId == b.Id)).Count(),
                DateModified = b.DateModified,
                Description = b.Description,
                SeoAlias = b.SeoAlias
            }).Take(5);

            model.BlogTags = (await _blogTagRepository.FindAll()).Take(10);

            HttpContext.Session.Set(CommonConstants.BlogId, id);
            model.Tags = (await _blogTagRepository.FindAll(x => x.BlogId == id)).Select(x => x.TagId).ToList();
            return(View(model));
        }