コード例 #1
0
        public ActionResult Edit(int id, Product product)
        {
            try
            {
                _productApp.Save(product);

                return RedirectToAction("Index");
            }
            catch
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
            }
        }
コード例 #2
0
        public ActionResult Create(Product product)
        {
            try
            {
                product.Id = 0;

                _productApp.Save(product);

                return RedirectToAction("Index");
            }
            catch
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
 public void Update(Product product)
 {
     _context.Execute("UPDATE Products SET Name=@Name, Price=@Price WHERE Id=@Id", product);
 }
コード例 #6
0
 public void Insert(Product product)
 {
     _context.Execute("INSERT INTO Products VALUES (@Name, @Price)", product);
 }