public async Task <IActionResult> Index() { var viewModel = new HomeIndexViewModel() { Carousel = _topService.GetPopularByLastMonth(5).Select(e => ClothesViewModel.CreateClothesView(e)), DiscountProducts = (await _clothes.GetTopDiscountClothes(4)).Select(e => ClothesViewModel.CreateClothesView(e)) }; return(View(viewModel)); }
public async Task <IActionResult> ClothesList(string category, string type, int?sort, int?costStart, int?costEnd, int page = 1) { try { int pageSize = 8; var clothes = await _clothes.GetClothesByTypeAndCategory(type, category); var count = clothes.Count(); var items = clothes.Skip((page - 1) * pageSize).Take(pageSize).ToList(); if (sort.HasValue) { if ((SortModeView)sort == SortModeView.CostAsc) { items = items.OrderBy(e => e.Cost).ToList(); } else if ((SortModeView)sort == SortModeView.CostDesc) { items = items.OrderByDescending(e => e.Cost).ToList(); } } if (costStart.HasValue && costStart > 0) { items = items.Where(e => e.Cost >= costStart).ToList(); } if (costEnd.HasValue && costEnd > 0) { items = items.Where(e => e.Cost <= costEnd).ToList(); } return(View(new ClothesListViewModel() { CategoryName = category, TypeName = type, Clothes = items.Select(e => ClothesViewModel.CreateClothesView(e)), PageModel = new PageViewModel(count, page, pageSize), EndCost = costEnd ?? 99999, StartCost = costStart ?? 0, Sort = (SortModeView)(sort ?? 0) })); } catch (ArgumentException) { return(NotFound()); } catch (Exception) { return(RedirectToAction("Error", "Home", new { message = "Не правильна категорія або тип одягу!" })); } }
public async Task <IActionResult> Details(int id, string returnUrl) { var clothes = await _clothesStore.GetById(id); if (clothes == null) { return(NotFound()); } var viewModel = new EditViewModel <ClothesViewModel> { ReturnUrl = returnUrl, Entity = ClothesViewModel.CreateClothesView(clothes) }; ViewBag.Sizes = viewModel.Entity.Sizes; return(View(viewModel)); }