public int AddProduct(Product product, ProductType productType, Macronutrient macronutrient) { if (product == null) { throw new Exception("Product object cannot by null."); } if (productType == null) { throw new Exception("ProductType object cannot by null."); } if (macronutrient == null) { throw new Exception("Macronutrient object cannot by null."); } product.Id = 0; product.ProductType = productType; product.ProductTypeId = productType.ProductTypeId; product.Macronutrient = macronutrient; product.MacronutrientId = macronutrient.MacronutrientId; _databaseContext.Products.Add(product); _databaseContext.SaveChanges(); return(product.Id); }
public void DeleteProduct(Product product, ProductType productType, Macronutrient macronutrient) { if (product == null) { throw new Exception("Product object cannot by null."); } if (productType == null) { throw new Exception("ProductType object cannot by null."); } if (macronutrient == null) { throw new Exception("Macronutrient object cannot by null."); } _databaseContext.Products.Remove(product); _databaseContext.SaveChanges(); _databaseContext.ProductTypes.Remove(productType); _databaseContext.SaveChanges(); _databaseContext.Macronutrients.Remove(macronutrient); _databaseContext.SaveChanges(); }
public IActionResult UpdateMacronutrient([FromBody] Macronutrient macronutrient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _macronutrientRepository.UpdateMacronutrient(macronutrient); return(new JsonResult(macronutrient.MacronutrientId)); }
public int UpdateMacronutrient(Macronutrient macronutrient) { if (macronutrient == null) { throw new Exception("Object cannot be null."); } _databaseContext.Macronutrients.Update(macronutrient); _databaseContext.SaveChanges(); return(macronutrient.MacronutrientId); }