public ActionResult EditCloth(int id) { var _cloth = _uow.Clothes.Get(id); var categories = _uow.Categories.GetAll();//.Categories; var cat = _cloth.Category; ViewBag.Categories = new SelectList(categories, "Name", "Name", cat.Name); var cvm = new ClothViewModel { ShortDescription = _cloth.ShortDescription, LongDescription = _cloth.LongDescription, Price = _cloth.Price, Name = _cloth.Name, InStock = _cloth.InStock, IsFavorite = _cloth.IsFavorite, CategoryName = _cloth.Category.Name, Id = _cloth.Id, ImageUrl = _cloth.ImageUrl, //ImageFile = _cloth. }; return(View(cvm)); }
public ActionResult EditCloth(ClothViewModel cvm) { if (ModelState.IsValid) { var cloth = _uow.Clothes.Get(cvm.Id); //.Find(c => c.Id == cvm.Id).FirstOrDefault(); var cat = _uow.Categories.Find(r => r.Name == cvm.CategoryName).FirstOrDefault(); //.Get(cvm.CategoryId); if (cloth != null) { string fileName = Path.GetFileNameWithoutExtension(cvm.ImageFile.FileName); string extension = Path.GetExtension(cvm.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; cvm.ImageUrl = fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); cloth.Name = cvm.Name; cloth.Price = cvm.Price; cloth.ShortDescription = cvm.ShortDescription; cloth.LongDescription = cvm.LongDescription; cloth.ImageUrl = cvm.ImageUrl; cloth.ImageThumbnailUrl = cvm.ImageUrl; if (cvm.ImageFile != null && cvm.ImageFile.ContentLength > 0) { cvm.ImageFile.SaveAs(fileName); } cloth.InStock = cvm.InStock; cloth.Category = cat; _uow.Commit(); TempData["message"] = $"{cloth.Name} was successfully edited."; } return(RedirectToAction("Index")); } else { return(View(cvm)); } }
public async Task <IActionResult> TakePrice(ClothViewModel clothViewModel) { if (clothViewModel.Close == true) { foreach (var cloth in clothViewModel.ClothList) { cloth.Price_RL = (cloth.Price * (1 - (0.01 * clothViewModel.Discount))); cloth.SoldDate = DateTime.Now; _context.Update(cloth); } await _context.SaveChangesAsync(); return(View("Index")); } if (clothViewModel.Back == "true") { var priceSubstract = clothViewModel.ClothList.LastOrDefault().Price; clothViewModel.ClothList.RemoveAt(clothViewModel.ClothList.Count - 1); clothViewModel.PriceCounter -= priceSubstract; clothViewModel.Back = "false"; return(View("Index", clothViewModel)); } var SingleCloth = await _context.Clothes.Where(c => c.Id == clothViewModel.Id).SingleOrDefaultAsync(); if (SingleCloth != null && SingleCloth.Sold == true) { TempData["ErrorMessage"] = "This is the message"; return(View("Index", clothViewModel)); } if (SingleCloth != null && !(clothViewModel.ClothList.Exists(x => x.Id == SingleCloth.Id))) { clothViewModel.PriceCounter = SingleCloth.Price + clothViewModel.PriceCounter; clothViewModel.ClothList.Add(SingleCloth); SingleCloth.Sold = true; return(View("Index", clothViewModel)); } return(View("Index", clothViewModel)); }
public ActionResult AddCloth(ClothViewModel cvm) { if (ModelState.IsValid) { var cat = _uow.Categories.Find(r => r.Name == cvm.CategoryName).FirstOrDefault();//_uow.Categories.Get(cvm.CategoryId); string fileName = Path.GetFileNameWithoutExtension(cvm.ImageFile.FileName); string extension = Path.GetExtension(cvm.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; cvm.ImageUrl = fileName;//"~/Content/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); //Save to the location on the directory cvm.ImageFile.SaveAs(fileName); var cloth = new Cloth { Name = cvm.Name, Price = cvm.Price, ShortDescription = cvm.ShortDescription, LongDescription = cvm.LongDescription, ImageUrl = cvm.ImageUrl, ImageThumbnailUrl = cvm.ImageUrl, InStock = cvm.InStock, Category = cat }; _uow.Clothes.Add(cloth); _uow.Commit(); TempData["message"] = string.Format("{0} has been saved.", cvm.Name); return(RedirectToAction("Index")); } else { //something went wrong with the form data values var categories = _uow.Categories.GetAll().Select(r => r.Name); ViewBag.Categories = new SelectList(categories); // ModelState.Errors. return(View(cvm)); } }
public async Task <IActionResult> TakePrice(ClothViewModel clothViewModel) { var SingleCloth = await _context.Clothes.Where(c => c.Id == clothViewModel.Id).SingleOrDefaultAsync(); clothViewModel.PriceCounter = SingleCloth.Price + clothViewModel.PriceCounter; clothViewModel.ClothList.Add(SingleCloth); SingleCloth.Sold = true; await _context.SaveChangesAsync(); //if (close == true) //{ // _context.Update(PC); //} return(View("Index", clothViewModel)); }