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

            if (deletedProduct != null)
            {
                TempData["message"] = $"{deletedProduct.Name} был удален";
            }
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        //Удаление продукта
        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);
        }
コード例 #4
0
        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 }));
        }
コード例 #5
0
 public IActionResult Edit(SushiBox sushiBox)
 {
     if (ModelState.IsValid)
     {
         repository.SaveProduct(sushiBox);
         TempData["message"] = $"{sushiBox.Name} был сохранен";
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(sushiBox));
     }
 }
コード例 #6
0
ファイル: CartSushiBox.cs プロジェクト: zrusakovv/DelClub
        //Добавление товара в корзину
        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;
            }
        }
コード例 #7
0
 //Сохранение продукта
 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();
 }
コード例 #8
0
ファイル: SessionSushiBox.cs プロジェクト: zrusakovv/DelClub
 public override void RemoveLine(SushiBox sushiBox)
 {
     base.RemoveLine(sushiBox);
     Session.SetJson("CartSushiBox", this);
 }
コード例 #9
0
ファイル: SessionSushiBox.cs プロジェクト: zrusakovv/DelClub
 public override void AddItem(SushiBox sushiBox, int quantity)
 {
     base.AddItem(sushiBox, quantity);
     Session.SetJson("CartSushiBox", this);
 }
コード例 #10
0
ファイル: CartSushiBox.cs プロジェクト: zrusakovv/DelClub
 //Удаление товара из корзины
 public virtual void RemoveLine(SushiBox sushiBox) => lineCollection.RemoveAll(l => l.SushiBox.Id == sushiBox.Id);