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