internal static IOrder ToOrder(this OrderDisplay orderDisplay, IOrder destination) { if (orderDisplay.Key != Guid.Empty) { destination.Key = orderDisplay.Key; } destination.OrderNumberPrefix = orderDisplay.OrderNumberPrefix; destination.OrderDate = orderDisplay.OrderDate; destination.OrderStatus = orderDisplay.OrderStatus.ToOrderStatus(); destination.VersionKey = orderDisplay.VersionKey; destination.Exported = orderDisplay.Exported; // TODO remove existing line items from destination not present in orderDisplay var items = destination.Items.Where(x => orderDisplay.Items.Any(display => display.Key == x.Key)); var collection = new LineItemCollection(); foreach (var item in items) { collection.Add(item); } ((Order)destination).Items = collection; return(destination); }
public ShipMethodDisplay GetShipMethod(OrderDisplay order) { var invoice = _invoiceService.GetByKey(order.InvoiceKey); if (invoice == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var shipmentLineItem = invoice.Items.FirstOrDefault(x => x.LineItemType == LineItemType.Shipping); if (shipmentLineItem == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var shipment = shipmentLineItem.ExtendedData.GetShipment<InvoiceLineItem>(); if (shipment == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if(shipment.ShipMethodKey != null) { var shipMethod = _shipMethodService.GetByKey(shipment.ShipMethodKey.Value); if (shipMethod == null) return new ShipMethodDisplay() {Name = "Not Found"}; return shipMethod.ToShipMethodDisplay(); } return new ShipMethodDisplay() { Name = "Not Found" }; }
internal static IOrder ToOrder(this OrderDisplay orderDisplay, IOrder destination) { if (orderDisplay.Key != Guid.Empty) { destination.Key = orderDisplay.Key; } destination.OrderNumberPrefix = orderDisplay.OrderNumberPrefix; destination.OrderDate = orderDisplay.OrderDate; destination.OrderStatus = orderDisplay.OrderStatus.ToOrderStatus(); destination.VersionKey = orderDisplay.VersionKey; destination.Exported = orderDisplay.Exported; // TODO remove existing line items from destination not present in orderDisplay return(destination); }
public ShipmentDisplay NewShipment(OrderDisplay order) { try { if(!order.Items.Any()) throw new InvalidOperationException("The shipment did not include any line items"); var merchOrder = _orderService.GetByKey(order.Key); var builder = new ShipmentBuilderChain(MerchelloContext, order.ToOrder(merchOrder)); var attempt = builder.Build(); if(!attempt.Success) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception)); return attempt.Result.ToShipmentDisplay(); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message))); } }