/// <summary> /// Gets a list of orders of a status. Some order details /// </summary> /// <param name="status">Status to search for</param> /// <returns>Model - list of orders, also status</returns> public OrdersModel GetOrders(string status) { var result = _apiService.GetRequest($"orders?direction=in&status={status.ToUpper()}"); var responseModel = JsonConvert.DeserializeObject <GetOrdersResponseModel>(result); var model = new OrdersModel(responseModel, status); foreach (var order in model.Orders) { var orderEntity = _dataService.GetOrder(order.OrderId) as Data.Entities.BricklinkOrder; if (orderEntity != null) { order.RealName = orderEntity.BuyerRealName; order.OrderIsLoaded = orderEntity.OrderItems.Any(); order.Id = orderEntity.Id; order.Weight = PostageHelper.FormatWeight(orderEntity.Weight); order.PackageSize = PostageHelper.GetPackageSize(orderEntity.ShippingMethod); order.ShippingMethod = PostageHelper.GetServiceCode(orderEntity.ShippingMethod); order.InternationalOrder = PostageHelper.IsInternational(orderEntity.ShippingMethod); } else { order.Id = _dataService.AddInitialOrder(order); } } return(model); }
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; }
public OrderCsvModel(GetOrderResponseModel model) { var data = model.data; if (data.shipping == null) { Name = "ERROR: Shipping was null!"; return; } if (data.shipping.address == null) { Name = "ERROR: Shipping address was null!"; return; } Name = data.shipping.address.name.full.HtmlDecode(); Address1 = data.shipping.address.address1.HtmlDecode(); Address2 = data.shipping.address.address2.HtmlDecode(); AddressCity = data.shipping.address.city.HtmlDecode(); AddressPostcode = data.shipping.address.postal_code.HtmlDecode(); AddressCounty = data.shipping.address.state.HtmlDecode(); AddressCountry = data.shipping.address.country_code; OrderReference = data.order_id.ToString(); OrderValue = StaticFunctions.FormatCurrency(data.cost?.grand_total ?? "0").ToString(); ShippingCost = StaticFunctions.FormatCurrency(data.cost?.shipping ?? "0").ToString(); Weight = PostageHelper.FormatWeight(data.total_weight); ServiceCode = PostageHelper.GetServiceCode(data.shipping.method); PackageSize = PostageHelper.GetPackageSize(data.shipping.method); ProductName = "Mixed Lego (No Batteries)"; UnitPrice = StaticFunctions.FormatCurrency(data.cost?.subtotal ?? "0").ToString(); Quantity = "1"; UnitWeight = Weight; //EmailAddress = data.buyer_email; //EmailNotification = !string.IsNullOrEmpty(data.buyer_email); CountryOfOrigin = "Denmark"; }
/// <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 }); }