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 ClothesViewModel GenerateVM() { ClothesViewModel clothesViewModel = new ClothesViewModel { Sizes = Sizes(), ItemNames = ItemNames(), Clothes = GetClothes() }; return(clothesViewModel); }
public IActionResult Add([FromBody] ClothesViewModel cvm) { if (cvm != null) { var item = TinyMapper.Map <ClothesItem>(cvm); item.CreatedDate = DateTime.Now; item.LastModifiedDate = DateTime.Now; DbContext.ClothesItems.Add(item); DbContext.SaveChanges(); return(new JsonResult(TinyMapper.Map <ClothesItem>(item), DefaultJsonSettings)); } return(new StatusCodeResult(500)); }
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 IActionResult Update(int id, [FromBody] ClothesViewModel cvm) { var item = DbContext.ClothesItems.Where(i => i.Id == id).FirstOrDefault(); if (item != null && cvm != null) { item.Description = cvm.Description; item.Shop = cvm.Shop; item.LastModifiedDate = DateTime.Now; DbContext.SaveChanges(); return(new JsonResult(TinyMapper.Map <ClothesViewModel>(item), DefaultJsonSettings)); } return(NotFound(new { Error = string.Format("Item Id {0} has not been found", id) })); }
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)); }
public ActionResult Edit(ClothesViewModel model) { var editStudent = _context.Clothes.FirstOrDefault(t => t.Id == model.Id); if (editStudent != null) { editStudent.Name = model.Name; editStudent.Price = model.Price; editStudent.URL_Image = model.URL_Image; editStudent.Color = model.Color; editStudent.Size = model.Size; editStudent.Details = model.Details; _context.SaveChanges(); return(RedirectToAction("Index", "Clothes")); } else { return(RedirectToAction("Index", "Clothes")); } }
private static void ClothesViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { UniformView uv = d as UniformView; if (uv == null) { return; } ClothesViewModel ovm = e.OldValue as ClothesViewModel; ClothesViewModel nvm = e.NewValue as ClothesViewModel; if (ovm != null && !ovm.CharacterViewModel.IsDisposed) { ovm.CharacterViewModel.Profile.Gender.PropertyChanged -= uv.GenderOnPropertyChanged; } if (nvm != null) { nvm.CharacterViewModel.Profile.Gender.PropertyChanged += uv.GenderOnPropertyChanged; } }
public async Task <IActionResult> Clothes(int genderId = 0, int categoryId = 0, int pageId = 1, int brandId = 0) { AppSetting setting = db.AppSettings.ToList().LastOrDefault(); List <Product> Products = await db.Products.ToListAsync(); if (brandId != 0) { Products = Products.Where(el => el.BrandId == brandId).ToList(); } if (genderId != 0) { Products = Products.Where(el => el.GenderId == genderId).ToList(); } int CountOfProducts = Products.Count; List <Category> Categ = await db.Categories.ToListAsync(); Category FillCat = Categ.FirstOrDefault(el => el.Id == categoryId); Categ = Categ.Where(el => Products.Contains(Products.FirstOrDefault(pr => pr.CategoryId == el.Id))).OrderBy(el => el.Name).ToList(); Dictionary <Category, int> Categories = new Dictionary <Category, int>(); foreach (var item in Categ) { Categories.Add(item, Products.Where(el => el.CategoryId == item.Id).Count()); } if (categoryId != 0) { Products = Products.Where(el => el.CategoryId == categoryId).ToList(); } int countProductsOnPage = (int)Math.Ceiling((double)Products.Count / setting.CountProductsOnPage); if (Products.Count > setting.CountProductsOnPage * pageId) { Products = Products.GetRange(setting.CountProductsOnPage * (pageId - 1), setting.CountProductsOnPage); } else { Products = Products.GetRange(setting.CountProductsOnPage * (pageId - 1), Products.Count - setting.CountProductsOnPage * (pageId - 1)); } Dictionary <int, string> ImgUrls = new Dictionary <int, string>(); foreach (var product in Products) { ImgUrls[product.Id] = JsonSerializer.Deserialize <string[]>(product.ImgUrls).FirstOrDefault(); } ClothesViewModel model = new ClothesViewModel { Products = Products, Categories = Categories, CountOfPages = countProductsOnPage, FillCat = FillCat, countOfProducts = CountOfProducts, genderId = genderId, pageId = pageId, categoryId = categoryId, brandId = brandId, ImgUrls = ImgUrls }; return(View(model)); }