public IActionResult CreateSalesOrder([FromBody] NewSalesOrderDto newOrder) { if (newOrder == null) { return(StatusCode(400)); } if (!ModelState.IsValid) { return(new InvalidInputResponse(ModelState)); } var client = _customerQuery.GetCustomerById(newOrder.ClientId); if (client == null) { ModelState.AddModelError("ClientId", $"Customer with id: {newOrder.ClientId} Not Found"); } var employee = _employeeQuery.GetEmployeeById(newOrder.CreatedBy); if (employee == null) { ModelState.AddModelError("CreatedBy", $"Employee with id: {newOrder.CreatedBy} Not Found"); } var salesOrder = _factory.CreateNewSaleOrder(newOrder); var result = _command.CreateSalesOrder(salesOrder); if (result == null) { return(StatusCode(500)); } return(StatusCode(201, result)); }
public CustomerOrder CreateNewSaleOrder(NewSalesOrderDto customerOrder) { CustomerOrder newOrder = new CustomerOrder() { ClientId = customerOrder.ClientId, CreatedBy = customerOrder.CreatedBy, OrderStatus = customerOrder.Status, Description = customerOrder.Description, DueDate = customerOrder.DeliveryDate, }; foreach (var item in customerOrder.purchaseOrderDetail) { newOrder.CustomerOrderItem.Add(new CustomerOrderItem() { ItemId = item.ItemId, Quantity = item.Quantity, PricePerItem = item.UnitPrice, DueDate = item.DueDate }); } return(newOrder); }