//Метод обработки нажатия на кнопк, удаления товара public RedirectToActionResult RemoveFromCart(int Id, string returnUrl) { SushiBox sushiBox = repository.SushiBoxes.FirstOrDefault(p => p.Id == Id); if (sushiBox != null) { cart.RemoveLine(sushiBox); } return(RedirectToAction("SushiBoxList", new { returnUrl })); }
public IActionResult Delete(int Id) { SushiBox deletedProduct = repository.DeleteProduct(Id); if (deletedProduct != null) { TempData["message"] = $"{deletedProduct.Name} был удален"; } return(RedirectToAction("Index")); }
//Удаление продукта public SushiBox DeleteProduct(int Id) { SushiBox dbEntry = context.SushiBoxes.FirstOrDefault(p => p.Id == Id); if (dbEntry != null) { context.SushiBoxes.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public RedirectToActionResult AddToCart(int Id, string returnUrl) { SushiBox sushiBox = repository.SushiBoxes .FirstOrDefault(p => p.Id == Id); if (sushiBox != null) { cart.AddItem(sushiBox, 1); } return(RedirectToAction("SushiBoxList", new { returnUrl })); }
public IActionResult Edit(SushiBox sushiBox) { if (ModelState.IsValid) { repository.SaveProduct(sushiBox); TempData["message"] = $"{sushiBox.Name} был сохранен"; return(RedirectToAction("Index")); } else { return(View(sushiBox)); } }
//Добавление товара в корзину public virtual void AddItem(SushiBox sushiBox, int quantity) { SBCartLine line = lineCollection .Where(p => p.SushiBox.Id == sushiBox.Id).FirstOrDefault(); if (line == null) { lineCollection.Add(new SBCartLine { SushiBox = sushiBox, Quantity = quantity }); } else { line.Quantity += quantity; } }
//Сохранение продукта public void SaveProduct(SushiBox sushiBox) { if (sushiBox.Id == 0) { context.SushiBoxes.Add(sushiBox); } else { SushiBox dbEntry = context.SushiBoxes.FirstOrDefault(p => p.Id == sushiBox.Id); if (dbEntry != null) { dbEntry.Img = sushiBox.Img; dbEntry.Name = sushiBox.Name; dbEntry.Description = sushiBox.Description; dbEntry.Category = sushiBox.Category; dbEntry.Price = sushiBox.Price; } } context.SaveChanges(); }
public override void RemoveLine(SushiBox sushiBox) { base.RemoveLine(sushiBox); Session.SetJson("CartSushiBox", this); }
public override void AddItem(SushiBox sushiBox, int quantity) { base.AddItem(sushiBox, quantity); Session.SetJson("CartSushiBox", this); }
//Удаление товара из корзины public virtual void RemoveLine(SushiBox sushiBox) => lineCollection.RemoveAll(l => l.SushiBox.Id == sushiBox.Id);