public IActionResult Add([FromBody] OrderRegisterModel model) { if (ModelState.IsValid) { _orderOperations.AddOrder(model); } else { return(BadRequest()); } return(Ok()); }
public void AddOrder(OrderRegisterModel model) { Context.Orders.Add(new Order { CustomerId = model.CustomerId, EmployeeId = model.EmployeeId, Freight = model.Freight, ShipAddress = model.ShipAddress, ShipName = model.ShipName, ShipCountry = model.ShipCountry, ShipCity = model.ShipCity }); }
public void AddOrder(OrderRegisterModel model) { _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} started"); var customer = _repositories.Customers.GetSingle(u => u.CustomerId == model.CustomerId); if (customer == null) { throw new LogicException("There is no customer with that Id"); } var employee = _repositories.Employees.Get(model.EmployeeId); if (employee == null) { throw new LogicException("There is no employee with that Id"); } _repositories.Orders.AddOrder(model); _repositories.SaveChanges(); _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} finished"); }