예제 #1
0
 public void CreateProduct(ProductUpdateDtos products)
 {
     if (products == null)
     {
         throw new ArgumentNullException(nameof(products));
     }
     _context.Products.Add(products);
     SaveChanges();
 }
예제 #2
0
        public void UpdateProduct(int ProductID, ProductUpdateDtos products)
        {
            var updateProducts = GetProductByID(ProductID);

            if (updateProducts == null)
            {
                _logger.LogInformation("No Product available");
            }
            var updateProductText = "Update dbo.Products SET ProductName = @ProductName, ProductPrice = @ProductPrice, Active = @Active, ModifiedDate = @ModifiedDate, ModifiedBy = @ModifiedBy Where ProductID = @ProductIDParam";
            var ProductName       = new SqlParameter("@ProductName", products.ProductName);
            var ProductPrice      = new SqlParameter("@ProductPrice", products.ProductPrice);
            var Active            = new SqlParameter("@Active", products.Active);
            var ModifiedDate      = new SqlParameter("@ModifiedDate", DateTime.Now);
            var ModifiedBy        = new SqlParameter("@ModifiedBy", "Admin");
            var ProductIDParam    = new SqlParameter("@ProductIDParam", ProductID);
            int noOfRowUpdated    = _context.Database.ExecuteSqlCommand(updateProductText, ProductName, ProductPrice, Active, ModifiedDate, ModifiedBy, ProductIDParam);
        }
 public ActionResult <ProductUpdateDtos> UpdateProducts(int ProductID, ProductUpdateDtos productUpdateDtos)
 {
     _writeRepository.UpdateProduct(ProductID, productUpdateDtos);
     return(NoContent());
 }
        public ActionResult <Products> CreateProduct(ProductUpdateDtos productCreateDtos)
        {
            _writeRepository.CreateProduct(productCreateDtos);

            return(Ok());
        }