示例#1
0
 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;
 }
示例#2
0
        //Метод обработки нажатия на кнопк, удаления товара
        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 }));
        }
示例#3
0
        public IActionResult Delete(int Id)
        {
            Kfc deletedProduct = repository.DeleteProduct(Id);

            if (deletedProduct != null)
            {
                TempData["message"] = $"{deletedProduct.Name} был удален";
            }
            return(RedirectToAction("Index"));
        }
示例#4
0
        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 }));
        }
示例#5
0
        //Удаление продукта
        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);
        }
示例#6
0
 public IActionResult Edit(Kfc kfc)
 {
     if (ModelState.IsValid)
     {
         repository.SaveProduct(kfc);
         TempData["message"] = $"{kfc.Name} был сохранен";
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(kfc));
     }
 }
示例#7
0
        //Добавление товара в корзину
        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;
            }
        }
示例#8
0
 //Сохранение продукта
 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();
 }
示例#9
0
 //Удаление товара из корзины
 public virtual void RemoveLine(Kfc kfc) => lineCollection.RemoveAll(l => l.Kfc.Id == kfc.Id);
示例#10
0
 public override void RemoveLine(Kfc kfc)
 {
     base.RemoveLine(kfc);
     Session.SetJson("CartKfc", this);
 }
示例#11
0
 public override void AddItem(Kfc kfc, int quantity)
 {
     base.AddItem(kfc, quantity);
     Session.SetJson("CartKfc", this);
 }