public void Add(ProductRegisterModel model) { _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} started"); var supplier = _repositories.Suppliers.Get((int)model.SupplierId); if (supplier == null) { throw new LogicException("There is no supplier with that Id"); } var category = _repositories.Categories.Get((int)model.CategoryId); if (category == null) { throw new LogicException("There is no category with that Id"); } _repositories.Products.Add(new Product { CategoryId = model.CategoryId, Discontinued = model.Discontinued, ProductName = model.ProductName, QuantityPerUnit = model.QuantityPerUnit, SupplierId = model.SupplierId, UnitPrice = model.UnitPrice, UnitsInStock = model.UnitsInStock }); _repositories.SaveChanges(); _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} finished"); }
public IActionResult Post([FromBody] ProductRegisterModel model) { if (ModelState.IsValid) { _productOperations.Add(model); } else { return(BadRequest("Not all properties have filled")); } return(Created("", model)); }