public ActionResult Create(Product product)
        {
            Shop.CreateProduct(product.Name, product.Description, 
                product.Price, product.Weight, product.Image);

            return RedirectToAction("Index");
        }
Example #2
0
        public static Product CreateProduct(string name, string description, decimal price, decimal weight, string image)
        {
            using (var db = new ShopModel())
            {
                var p = new Product
                {
                    Name = name,
                    Description = description,
                    Weight = weight,
                    Price = price,
                    Image = image
                };
                db.Products.Add(p);
                db.SaveChanges();

                return p;
            }
        }
Example #3
0
        public static void UpdateProduct(Product updatedProduct)
        {
            using (var db = new ShopModel())
            {
                var product = db.Products.
                    Where(p => p.ProductId == updatedProduct.ProductId).FirstOrDefault();
                if (product == null)
                    return;

                var originalProduct = product;
                product.Name = updatedProduct.Name;
                product.Price = updatedProduct.Price;
                product.Weight = updatedProduct.Weight;
                product.Image = updatedProduct.Image;
                product.Description = updatedProduct.Description;

                db.Entry(originalProduct).CurrentValues.SetValues(product);
                db.SaveChanges();

            }
        }
Example #4
0
 public static void DeleteProduct(Product product)
 {
     using (var db = new ShopModel())
     {
         db.Products.Remove(product);
         db.SaveChanges();
     }
 }
 public ActionResult Delete(Product product)
 {
     Shop.DeleteProduct(product);
     return RedirectToAction("Index");
 }
 public ActionResult Edit(Product product)
 {
     Shop.UpdateProduct(product);
     return RedirectToAction("Index");
 }