public bool Update(Product product)
        {
            using (var context = new StoreContext())
            {
                var oldProduct = context.Products.FirstOrDefault(p => p.Id == product.Id);

                try
                {
                    if (oldProduct == null || oldProduct.Id == 0)
                        return false;
                    else
                    {
                        oldProduct.Name = product.Name;
                        oldProduct.Description = product.Description;
                        oldProduct.CategoryId = product.CategoryId;
                        oldProduct.ActiveDate = product.ActiveDate;
                        oldProduct.UnitPrice = product.UnitPrice;
                        oldProduct.IsActive = product.IsActive;

                        context.SaveChanges();
                        Clients.productUpdated(oldProduct);
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    Caller.reportError("Oops! Unable to update product: " + ex);
                    return false;
                }
            }
        }
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
            return View(product);
        }
 public bool Add(Product product)
 {
     try
     {
         using (var context = new StoreContext())
         {
             Product savedProduct = context.Products.Add(product);
             context.SaveChanges();
             Clients.productAdded(savedProduct);
             return true;
         }
     }
     catch (Exception ex)
     {
         Caller.reportError("Oops! Unable to add product: " + ex);
         return false;
     }
 }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return View(product);
 }
 private void UpdateProduct(Product product)
 {
     db.Entry(product).State = EntityState.Modified;
     db.SaveChanges();
 }
 private void InsertProduct(Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
 }
 private void DeleteProduct(Product product)
 {
     Product repoProduct = db.Products.Find(product.Id);
     db.Products.Remove(repoProduct);
     db.SaveChanges();
 }