public IActionResult NewsOverview(int pageNumber, string category, [FromServices] GetNews getNews) { if (pageNumber < 1) { return(RedirectToAction("NewsOverview", new { pageNumber = 1, category })); } var news = string.IsNullOrEmpty(category) ? getNews.Do(PageSize, pageNumber) : getNews.Do(PageSize, pageNumber, category); int newsCount = string.IsNullOrEmpty(category) ? getNews.Count() : getNews.Count(category); int skipAmount = PageSize * (pageNumber - 1); int capacity = skipAmount + PageSize; var newsVm = new List <NewsViewModel>(); foreach (var singleNews in news) { newsVm.Add(new NewsViewModel { Id = singleNews.Id, Title = singleNews.Title, Body = singleNews.Body, ImagePath = singleNews.Image, Created = singleNews.Created, Description = singleNews.Description, Tags = singleNews.Tags, Category = singleNews.Category }); } newsVm = newsVm.OrderByDescending(x => x.Created).ToList(); var viewModel = new NewsPageViewModel { News = newsVm, PageNumber = pageNumber, Category = category, PageCount = (int)Math.Ceiling((double)newsCount / PageSize) }; if (newsCount > capacity) { viewModel.NextPage = true; } return(View(viewModel)); }
public void OnGet([FromServices] GetProducts getProducts, [FromServices] GetNews getNews) { News = getNews.Do().ToList(); foreach (Shops shop in (Shops[])Enum.GetValues(typeof(Shops))) { var countSale = getProducts.CountProductOnSaleForShop(shop.ToString()); if (countSale != 0) { var shopVm = new ShopViewModel { Name = shop.ToString(), SmallImagePath = $"{shop}-s.jpg", LargeImagePath = $"{shop}.jpg" }; ProductsOnSale.Add(shop.ToString(), countSale); Shops.Add(shopVm); } } }
public IActionResult Index([FromServices] GetNews getNews) { var news = getNews.Do(); var viewModels = new List <NewsViewModel>(); foreach (var singleNews in news) { viewModels.Add(new NewsViewModel { Id = singleNews.Id, Title = singleNews.Title, Body = singleNews.Body, ImagePath = singleNews.Image, Created = singleNews.Created, Description = singleNews.Description, Tags = singleNews.Tags, Category = singleNews.Category }); } return(View(viewModels)); }