Ejemplo n.º 1
0
        public ActionResult Edit(Product product)
        {
            if(ModelState.IsValid == true)
            {
                repository.Save(product);
                TempData["message"] = "Produkt został zapisany w bazie danych";

                return RedirectToAction("Index");
            }

            return View(product);
        }
Ejemplo n.º 2
0
        public void AddItem(Product product, int quantity)
        {
            CartItem item = itemsList.Where(p => p.CartProduct.ProductId == product.ProductId).FirstOrDefault();

            if (item == null)
            {
                itemsList.Add(new CartItem { CartProduct = product, Quantity = quantity });
            }
            else
            {
                item.Quantity += quantity;
            }
        }
Ejemplo n.º 3
0
        public void Save(Product product)
        {
            if(product.ProductId == 0)
            {
                context.Products.Add(product);
            }
            else
            {
                Product dbEntry = context.Products.Find(product.ProductId);
                if(dbEntry != null)
                {
                    dbEntry.Album = product.Album;
                    dbEntry.Author = product.Author;
                    dbEntry.Category = product.Category;
                    dbEntry.Price = product.Price;
                }
            }

            context.SaveChanges();
        }
Ejemplo n.º 4
0
 public void RemoveItem(Product product)
 {
     itemsList.RemoveAll(p => p.CartProduct.ProductId == product.ProductId);
 }