public ActionResult Edit(int id, Product product) { try { _productApp.Save(product); return RedirectToAction("Index"); } catch { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } }
public ActionResult Create(Product product) { try { product.Id = 0; _productApp.Save(product); return RedirectToAction("Index"); } catch { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } }
public Product Save(Product product) { // if is new product if (product.Id > 0) { // update data _productRepository.Update(product); } else { // insert data _productRepository.Insert(product); } return product; }
public Product Save(Product product) { try { // Create unit of work (begins transaction) using (var uow = _uoWFactory.Create()) { // save product (with transaction) _productService.Save(product); // commit transation // (ATTENTION: Call the SaveChanges method always the end of the scope of the unit. // If not called, the Dispose of the unit of work will execute the transaction rollback.) uow.SaveChanges(); } return product; } catch (Exception ex) { // log error throw; } }
public void Update(Product product) { _context.Execute("UPDATE Products SET Name=@Name, Price=@Price WHERE Id=@Id", product); }
public void Insert(Product product) { _context.Execute("INSERT INTO Products VALUES (@Name, @Price)", product); }