示例#1
0
        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);
        }
示例#2
0
        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();
        }
示例#3
0
        public IActionResult UpdateMacronutrient([FromBody] Macronutrient macronutrient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _macronutrientRepository.UpdateMacronutrient(macronutrient);
            return(new JsonResult(macronutrient.MacronutrientId));
        }
示例#4
0
        public int UpdateMacronutrient(Macronutrient macronutrient)
        {
            if (macronutrient == null)
            {
                throw new Exception("Object cannot be null.");
            }

            _databaseContext.Macronutrients.Update(macronutrient);
            _databaseContext.SaveChanges();
            return(macronutrient.MacronutrientId);
        }