public ActionResult Create(Product product)
 {
     if (ModelState.IsValid) {
         _productService.InsertOrUpdate(product);
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
        public void InsertOrUpdate(Product product)
        {
            if (product.ProductId == default(int))
            {
                // New entity
                _context.Products.Add(product);
            }
            else
            {
                // Existing entity
                if (_context.Products.Any(x => x.ProductId != product.ProductId))
                {
                    throw new ObjectNotFoundException(Business.Domain.Resources.Errors.Product_Update_EntityNotFound);
                }

                _context.Entry(product).State = EntityState.Modified;
            }
        }
Exemplo n.º 3
0
 public void InsertOrUpdate(Product product)
 {
     _productRepository.InsertOrUpdate(product);
     _productRepository.Save();
 }