示例#1
0
        public async Task <IActionResult> Index(string categoryId = "")
        {
            var homepageViewModel = new HomePageViewModel()
            {
                Categories = (await _categoryService.Gets()).Select(c => new  Models.CategoryViewModels.CategoryViewModel
                {
                    CategoryId  = c.Id,
                    Description = c.Description,
                    Name        = c.Name
                }).ToList(),
                Posts = (await _homePageService.FilterPostByCategoryId(categoryId, _userManager.GetUserId(HttpContext.User)))
                        .Select(p => new PostViewModel
                {
                    CategoryId       = p.CategoryId,
                    Id               = p.Id,
                    Content          = p.Content,
                    CreatedDate      = p.CreatedDate,
                    ShortDescription = p.ShortDescription,
                    ThumbnailImage   = p.ThumbnailImage,
                    Title            = p.Title,
                    UpdatedDate      = p.UpdatedDate,
                    Slug             = p.Slug
                }).ToList()
            };

            return(View(homepageViewModel));
        }