public ProductDBInfo UpdateSingleProduct(int productId, ProductDBInfo updatedProduct) { var sql = @"update Products set Title=@Title, [Description]=@Description, Quantity=@Quantity, Price=@Price, imageUrl=@imageUrl, InStock=@InStock, ProductTypeId=@ProductTypeId, AnimalTypeId=@AnimalTypeId where ProductId=@ProductId"; using (var db = new SqlConnection(ConnectionString)) { var parameters = new { Title = updatedProduct.Title, Description = updatedProduct.Description, Quantity = updatedProduct.Quantity, Price = updatedProduct.Price, ImageUrl = updatedProduct.ImageUrl, InStock = updatedProduct.InStock, ProductTypeId = updatedProduct.ProductTypeId, AnimalTypeId = updatedProduct.AnimalTypeId, ProductId = productId }; var result = db.QueryFirstOrDefault <ProductDBInfo>(sql, parameters); return(result); } }
public ProductDBInfo AddProduct(ProductDBInfo productToAdd) { var sql = @$ "insert into Products(ProductTypeId, AnimalTypeId, Title, [Description], Quantity, Price, imageUrl, inStock, DateAdded) OUTPUT INSERTED.* values (@ProductTypeId, @AnimalTypeId, @Title, @Description, @Quantity, @Price, @imageUrl, @InStock, '{DateTime.Now.ToShortDateString()}')"; using (var db = new SqlConnection(ConnectionString)) { var result = db.QueryFirstOrDefault <ProductDBInfo>(sql, productToAdd); return(result); } }
public IActionResult AddProduct(ProductDBInfo productToAdd) { var result = _productRepository.AddProduct(productToAdd); return(Ok(result)); }
public IActionResult UpdateSingleProduct(int productId, ProductDBInfo updatedProduct) { var newProduct = _productRepository.UpdateSingleProduct(productId, updatedProduct); return(Ok(newProduct)); }