private void AddRequestToOrder(OrderRequest request, SalesOrderHeader order) { foreach (var requestedProduct in request.Products) { SalesOrderDetail line = new SalesOrderDetail { ProductID = requestedProduct.Product.ProductId.Value //TODO copy other info }; order.SalesOrderDetails.Add(line); } }
public SalesOrderResult PlaceOrder(string customerName, OrderRequest request) { Customer c = GetCustomer(customerName); if (c == null) { return new SalesOrderResult { State = OrderResultState.Invalid, Message = "Customer not found" } } ; bool isValid = ValidateOrderRequest(c, request); if (isValid) { using (IUnitOfWork uof = repository.CreateUnitOfWork()) { SalesOrderHeader order = uof.GetEntities <SalesOrderHeader>() .FirstOrDefault(o => o.CustomerID == c.CustomerID && o.OrderDate.Month == DateTime.Now.Month); if (order == null) { order = new SalesOrderHeader { Customer = c, OrderDate = DateTime.Now.Date }; uof.Add(order); } AddRequestToOrder(request, order); uof.SaveChanges(); return(new SalesOrderResult { State = OrderResultState.Placed, OrderId = order.SalesOrderID }); } } return(new SalesOrderResult { State = OrderResultState.Invalid }); }