public OrderWithItemsModel(GetOrderResponseModel order, GetOrderItemsResponseModel orderItems) { var data = order.data; BuyerName = data.shipping.address.name.full; UserName = data.buyer_name; ShippingMethod = PostageHelper.FriendlyPostageName(data.shipping.method); OrderTotal = data.cost.subtotal; Buyer = new Buyer(data.shipping.address); OrderNumber = data.order_id.ToString(); OrderDate = data.date_ordered.ToString("yyyy-MM-dd"); OrderPaid = data.payment.date_paid.ToString("yyyy-MM-dd"); SubTotal = StaticFunctions.FormatCurrencyStr(data.cost.subtotal); ServiceCharge = StaticFunctions.FormatCurrencyStr(data.cost.etc1); Coupon = StaticFunctions.FormatCurrencyStr(data.cost.coupon); PostagePackaging = StaticFunctions.FormatCurrencyStr(data.cost.shipping); Total = StaticFunctions.FormatCurrencyStr(data.cost.grand_total); Items = orderItems.data .SelectMany(x => x) .Select(x => new OrderItemModel(x)) .OrderBy(x => x.Condition) .ThenBy(x => x.RemarkLetter3) .ThenBy(x => x.RemarkLetter2) .ThenBy(x => x.RemarkLetter1) .ThenBy(x => x.RemarkNumber) .ThenBy(x => x.Colour) .ThenBy(x => x.Name); Messages = new List <BricklinkMessage>(); }
public EbayOrdersListItemModel(GetOrderResponseModel data) { OrderId = data.orderId; LegacyOrderId = data.legacyOrderId; OrderDate = data.creationDate; Status = data.orderFulfillmentStatus; BuyerUsername = data.buyer.username; PriceSubtotal = data.pricingSummary.priceSubtotal.ToString(); PriceDiscount = data.pricingSummary.priceDiscount?.ToString(); PriceDelivery = StaticFunctions.FormatCurrencyStr(decimal.Parse(data.pricingSummary.deliveryCost.convertedFromValue) - decimal.Parse(data.pricingSummary.deliveryDiscount?.convertedFromValue ?? "0")); PriceTotal = data.pricingSummary.total.ToString(); if (data.fulfillmentStartInstructions.Any() && data.fulfillmentStartInstructions[0].shippingStep != null) { BuyerName = data.fulfillmentStartInstructions[0].shippingStep.shipTo.fullName; ShippingMethod = PostageHelper.FriendlyPostageName(data.fulfillmentStartInstructions[0].shippingStep.shippingServiceCode); } ItemCount = data.lineItems.Sum(x => x.quantity); Items = data.lineItems.Select(x => new EbayOrdersListItemItemModel(x)); Cancelled = data.cancelStatus.cancelState != "NONE_REQUESTED"; PaymentStatus = data.orderPaymentStatus; }
/// <summary> /// Gets an order with its order items /// </summary> /// <param name="orderId">Order Id</param> /// <returns>Model with order and items</returns> public OrderWithItemsModel GetOrderWithItems(string orderId, int id = 0) { var order = _apiService.GetRequest <GetOrderResponseModel>("orders/" + orderId); var orderItems = _apiService.GetRequest <GetOrderItemsResponseModel>("orders/" + orderId + "/items"); // Add order to the DB var orderEntity = _dataService.AddOrder(order, orderItems, id); // Items come through in a very strange format, so get them from the DB after having just added them to the DB. var items = orderItems.data .SelectMany(x => x) .Select(item => { // Find this item in the DB var itemEntity = orderEntity.OrderItems.FirstOrDefault(x => x.Part.InventoryId == item.inventory_id); var unitPrice = decimal.Parse(item.unit_price_final); var totalPrice = unitPrice * item.quantity; int quantity; string image; var partModel = _dataService.GetPartModel(item.inventory_id, updateInvDate: order.data.date_ordered); if (partModel == null) { partModel = _dataService.GetPartModel(item.item.no, item.color_id, item.item.type, item.new_or_used, description: item.description, updateInvDate: order.data.date_ordered); } PartInventory inv = partModel?.PartInventory; if (inv != null) { image = inv.Image; quantity = inv.Quantity; } else if (itemEntity != null) { quantity = itemEntity.Quantity; image = _apiService.GetItemImage(item.item.type, item.item.no, item.color_id); } else { quantity = 0; image = _apiService.GetItemImage(item.item.type, item.item.no, item.color_id); } var itemModel = new OrderItemModel { InventoryId = item.inventory_id.ToString(), Name = HttpUtility.HtmlDecode(item.item.name), Condition = item.new_or_used == "N" ? "New" : "Used", Colour = item.color_name, Remarks = item.remarks, Quantity = item.quantity, UnitPrice = unitPrice, TotalPrice = totalPrice, Description = item.description, Type = item.item.type, Weight = item.weight, ItemsRemaining = quantity, Image = image }; if (inv != null && order.data.date_ordered > inv.LastUpdated) { // Update the inventory from the info we have in this order _dataService.UpdatePartInventoryFromOrder(inv, item.remarks, item.unit_price_final, item.description, item.inventory_id); } else if (inv == null) { AddPartInventoryFromOrder(item); } // Works out some stuff related to the remarks and the location ordering itemModel.FillRemarks(); return(itemModel); }) .OrderBy(x => x.Condition) .ThenBy(x => x.RemarkLetter3) .ThenBy(x => x.RemarkLetter2) .ThenBy(x => x.RemarkLetter1) .ThenBy(x => x.RemarkNumber) .ThenBy(x => x.Colour) .ThenBy(x => x.Name) .ToList(); var data = order.data; return(new OrderWithItemsModel { BuyerName = orderEntity.BuyerName, UserName = data.buyer_name, ShippingMethod = PostageHelper.FriendlyPostageName(orderEntity.ShippingMethod), OrderTotal = orderEntity.Subtotal.ToString(), Buyer = new Buyer(data.shipping.address), OrderNumber = orderEntity.OrderId, OrderDate = orderEntity.OrderDate.ToString("yyyy-MM-dd"), OrderPaid = data.payment.date_paid.ToString("yyyy-MM-dd"), OrderRemarks = data.remarks, SubTotal = StaticFunctions.FormatCurrencyStr(data.cost.subtotal), ServiceCharge = StaticFunctions.FormatCurrencyStr(data.cost.etc1), Coupon = StaticFunctions.FormatCurrencyStr(data.cost.coupon), PostagePackaging = StaticFunctions.FormatCurrencyStr(data.cost.shipping), Total = StaticFunctions.FormatCurrencyStr(data.cost.grand_total), Items = items }); }