public RedirectResult Checkout() { if (Session["goods"] != null) { db.Orders.Add(new Order { Location = HttpContext.Request.Cookies["location"]?.Value, DateTime = DateTime.Now }); db.SaveChanges(); int orderId = db.Orders.ToList().Last().OrderId; WatchOrdList listWO = JsonSerializer.Deserialize <WatchOrdList>(Session["goods"].ToString()); foreach (var WO in listWO) { db.Purchase.Add(new Purchase { OrderID = orderId, WatchId = WO.Watch.Id, Quantity = WO.Quantity }); } db.SaveChanges(); Session.Remove("goods"); } return(Redirect("/Cart")); }
public int Add(ProductEntity model) { using (_context) { _context.Products.Add(model); _context.SaveChanges(); return(model.Id); } }
public ActionResult Create(Review review) { if (ModelState.IsValid) { db.Reviews.Add(review); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(review)); }
public ActionResult Create(Choose choose) { if (ModelState.IsValid) { db.Chooses.Add(choose); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(choose)); }
public ActionResult Create(Feature feature) { if (ModelState.IsValid) { db.Features.Add(feature); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(feature)); }
public ActionResult Create(Grade grade) { if (ModelState.IsValid) { db.Grades.Add(grade); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(grade)); }
public ActionResult Create(Update update) { if (ModelState.IsValid) { db.Updates.Add(update); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(update)); }
public ActionResult Create(Watch watch) { if (ModelState.IsValid) { db.Watches.Add(watch); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(watch)); }
public ActionResult Create(TypeWatch typeWatch) { if (ModelState.IsValid) { db.TypesWatches.Add(typeWatch); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ChooseID = new SelectList(db.Chooses, "ChooseID", "ChooseID", typeWatch.ChooseID); return(View(typeWatch)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FeatureID = new SelectList(db.Features, "FeatureID", "FeatureID", product.FeatureID); ViewBag.TypeWatchID = new SelectList(db.TypesWatches, "TypeWatchID", "TypeWatchID", product.TypeWatchID); return(View(product)); }
public async Task <IActionResult> Edit(HomePageVM homePageVM) { Product product = await _context.Products.FindAsync(homePageVM.Product.Id); var image = _context.Images.Where(i => i.ProductId == product.Id).ToList(); HomePageVM homePageVMs = new HomePageVM() { Product = product, Images = image }; if (!ModelState.IsValid) { return(View(homePageVMs)); } var productDb = await _context.Products.FindAsync(homePageVM.Product.Id); if (homePageVM.ProductPhotos != null) { try { var ImgList = _context.Images.Where(v => v.ProductId == productDb.Id).ToList(); for (int i = 0; i < homePageVM.ProductPhotos.Count; i++) { IFormFileExstensions.Delete(_env.WebRootPath, "images", ImgList[i].ProductImage); var newPhoto = await homePageVM.ProductPhotos[i].SaveFileAsync(_env.WebRootPath, "images"); ImgList[i].ProductImage = newPhoto; _context.SaveChanges(); } } catch (Exception e) { ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again."); return(View(homePageVMs)); } } productDb.Name = homePageVM.Product.Name; productDb.Price = homePageVM.Product.Price; productDb.HasDiscount = homePageVM.Product.HasDiscount; productDb.DiscountedPrice = homePageVM.Product.DiscountedPrice; productDb.Color = homePageVM.Product.Color; productDb.Availability = homePageVM.Product.Availability; productDb.Status = true; productDb.InStock = homePageVM.Product.InStock; productDb.BrandId = homePageVM.Product.BrandId; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }