Exemplo n.º 1
0
 /// <summary>
 /// Creates a product
 /// </summary>
 /// <param name="productEntity"></param>
 /// <returns></returns>
 public int CreateProduct(BusinessEntities.ProductDto productEntity)
 {
     using (var scope = new TransactionScope())
     {
         var product = new Product
         {
             Name        = productEntity.Name,
             Description = productEntity.Description,
             Discount    = productEntity.Discount,
             Price       = productEntity.Price,
             Quantity    = productEntity.Quantity
         };
         _unitOfWork.ProductRepository.Insert(product);
         _unitOfWork.Save();
         scope.Complete();
         return(product.Id);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Updates a product
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="productEntity"></param>
        /// <returns></returns>
        public bool UpdateProduct(int productId, BusinessEntities.ProductDto productEntity)
        {
            var success = false;

            if (productEntity != null)
            {
                using (var scope = new TransactionScope())
                {
                    var product = _unitOfWork.ProductRepository.GetByID(productId);
                    if (product != null)
                    {
                        product.Name = productEntity.Name;
                        _unitOfWork.ProductRepository.Update(product);
                        _unitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return(success);
        }