コード例 #1
0
        public async Task <GetOrderResponseModel> GetOrder(Guid orderId)
        {
            try
            {
                Order order = await _orderRepository.GetOrder(orderId);

                var result = new GetOrderResponseModel()
                {
                    CreationDate = order.CreationDate.ToShortDateString(),
                    Id           = order.Id,
                    Name         = order.Name,
                    Status       = order.Status.ToString()
                };

                foreach (var product in order.ProductsList)
                {
                    var productModel = new GetOrderProductItem()
                    {
                        Name       = product.Name,
                        Price      = product.Price,
                        Quantity   = product.Quantity,
                        TotalPrice = product.TotalPrice
                    };

                    result.ProductsList.Add(productModel);
                }

                return(result);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(new GetOrderResponseModel());
            }
        }
コード例 #2
0
        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>();
        }
コード例 #3
0
 public EbayOrderModel(GetOrderResponseModel data, Data.Entities.EbayOrder orderEntity)
 {
     if (data.fulfillmentStartInstructions.Any() && data.fulfillmentStartInstructions[0].shippingStep?.shipTo?.contactAddress?.countryCode != "GB")
     {
         InitInternational(data, orderEntity);
     }
     else
     {
         Init(data, orderEntity);
     }
 }
コード例 #4
0
        /// <summary>
        /// Adds an order
        /// </summary>
        /// <param name="obj">Get Order Response model </param>
        /// <returns>Ebay Order Entity</returns>
        public EbayOrder AddOrder(GetOrderResponseModel obj)
        {
            var o = _orderRepo.FindOne(x => x.OrderId == obj.orderId) as EbayOrder;

            if (o != null)
            {
                return(o);
            }

            var entity = new EbayOrder
            {
                LegacyOrderId        = obj.legacyOrderId,
                SalesRecordReference = obj.salesRecordReference,
                OrderId       = obj.orderId,
                OrderDate     = obj.creationDate,
                BuyerUsername = obj.buyer.username,
                Subtotal      = obj.pricingSummary.priceSubtotal.ToDecimal(),
                Shipping      = obj.pricingSummary.deliveryCost.ToDecimal() - obj.pricingSummary.deliveryDiscount?.ToDecimal() ?? 0,
                Deductions    = obj.pricingSummary.priceDiscount?.ToDecimal() ?? 0,
                ExtraCosts    = obj.pricingSummary.adjustment?.ToDecimal() ?? 0,
                GrandTotal    = obj.pricingSummary.total?.ToDecimal() ?? 0,
                Status        = obj.cancelStatus.cancelState != "NONE_REQUESTED" ? OrderStatus.Cancelled : obj.orderFulfillmentStatus == "NOT_STARTED" ? OrderStatus.InProgress : OrderStatus.Complete
            };

            if (obj.fulfillmentStartInstructions != null && obj.fulfillmentStartInstructions.Any() && obj.fulfillmentStartInstructions?[0].shippingStep?.shipTo != null)
            {
                entity.BuyerName  = obj.fulfillmentStartInstructions?[0].shippingStep.shipTo.fullName;
                entity.BuyerEmail = obj.fulfillmentStartInstructions?[0].shippingStep.shipTo.email;
            }

            var items = obj.lineItems.Select(x => new EbayOrderItem
            {
                Order             = entity,
                LineItemId        = x.lineItemId,
                LegacyItemId      = x.legacyItemId,
                LegacyVariationId = x.legacyVariationId ?? "0",
                SKU           = x.sku,
                Image         = "",
                CharacterName = "",
                Name          = x.title,
                Quantity      = x.quantity,
                UnitPrice     = x.lineItemCost.ToDecimal()
            }).ToList();

            entity = _orderRepo.AddOrderWithItems(entity, items);

            return(_orderRepo.FindOne(x => x.Id == entity.Id) as EbayOrder);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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";
        }
コード例 #7
0
        private void Init(GetOrderResponseModel data, Data.Entities.EbayOrder orderEntity)
        {
            IsInternationalOrder = false;
            OrderNumber          = data.orderId;
            OrderDate            = data.creationDate.ToString("yyyy-MM-dd");
            if (data.paymentSummary.payments[0].paymentDate != DateTime.MinValue)
            {
                OrderPaid = data.paymentSummary.payments[0].paymentDate.ToString("yyyy-MM-dd");
            }
            else
            {
                OrderPaid = "";
            }
            SubTotal         = data.pricingSummary.priceSubtotal.ToString();
            PostagePackaging = data.pricingSummary.deliveryCost.Difference(data.pricingSummary.deliveryDiscount);
            if (data.pricingSummary.priceDiscount != null)
            {
                Discount = data.pricingSummary.priceDiscount.ToString();
            }
            else
            {
                Discount = "£0.00";
            }
            TotalDecimal = data.pricingSummary.total.ToCurrency();
            Total        = data.pricingSummary.total.ToString();
            if (data.pricingSummary.tax != null)
            {
                Tax = data.pricingSummary.tax.ToString();
            }
            if (data.fulfillmentStartInstructions.Any() && data.fulfillmentStartInstructions[0].shippingStep?.shipTo != null)
            {
                Buyer = new EbayOrderModelBuyer(data.fulfillmentStartInstructions[0].shippingStep.shipTo);
            }
            Items = data.lineItems.Select(x => new EbayOrderModelItem(x, orderEntity, false));

            HasDiscount = string.IsNullOrEmpty(Discount) || Items.Any(x => string.IsNullOrEmpty(x.Discount));
            HasVariants = Items.Any(x => !string.IsNullOrEmpty(x.LegacyVariationId));
        }
コード例 #8
0
        /// <summary>
        /// Adds an order into the DB. If it already exists, return it.
        /// </summary>
        /// <param name="order">Order response model from API</param>
        /// <param name="orderItems">Order items response model from API</param>
        /// <returns>A BL Order entity</returns>
        public Data.Entities.BricklinkOrder AddOrder(GetOrderResponseModel order, GetOrderItemsResponseModel orderItems, int id = 0)
        {
            var orderEntity = (id != 0 ?
                               _orderRepo.FindOne(id) :
                               _orderRepo.FindOne(x => x.OrderId == order.data.order_id.ToString()))
                              as Data.Entities.BricklinkOrder;

            if (orderEntity == null)
            {
                throw new Exception("Order doesn't exist!!");                 // todo: do something about this
            }

            if (orderEntity.OrderItems.Any())
            {
                return(orderEntity);
            }

            orderEntity.Weight         = order.data.total_weight;
            orderEntity.ShippingMethod = order.data.shipping?.method;
            orderEntity.BuyerRealName  = order.data.shipping.address.name.full;
            orderEntity.BuyerEmail     = order.data.buyer_email;
            orderEntity.Subtotal       = decimal.Parse(order.data.cost.subtotal);
            orderEntity.Deductions     = decimal.Parse(order.data.cost.credit) + decimal.Parse(order.data.cost.coupon);
            orderEntity.Shipping       = decimal.Parse(order.data.cost.shipping);
            orderEntity.ExtraCosts     = decimal.Parse(order.data.cost.salesTax) + decimal.Parse(order.data.cost.vat_amount) +
                                         decimal.Parse(order.data.cost.etc1) + decimal.Parse(order.data.cost.etc2) + decimal.Parse(order.data.cost.insurance);
            orderEntity.GrandTotal = decimal.Parse(order.data.cost.grand_total);
            orderEntity.Status     = order.data.status == "CANCELLED" ? OrderStatus.Cancelled : OrderStatus.InProgress;

            var orderItemEntities = orderItems.data
                                    .SelectMany(x => x)
                                    .Select(x => new BricklinkOrderItem
            {
                Order     = orderEntity,
                Name      = x.item.name,
                Quantity  = x.quantity,
                UnitPrice = decimal.Parse(x.unit_price_final),
                Part      = GetPartInv(x, order)
            }).ToList();

            orderEntity = _orderRepo.AddOrderWithItems(orderEntity, orderItemEntities);

            return(_orderRepo.FindOne(x => x.Id == orderEntity.Id) as Data.Entities.BricklinkOrder);

            PartInventory GetPartInv(OrderItemResponseModel item, GetOrderResponseModel ord)
            {
                var model = GetPartModel(item.inventory_id, updateInvDate: order.data.date_ordered);

                if (model != null)
                {
                    return(model.PartInventory);
                }

                model = GetPartModel(item.item.no, item.color_id, item.item.type, item.new_or_used, description: item.description);
                if (!model.InvIsPlaceHolder)
                {
                    return(model.PartInventory);
                }

                model = AddInventoryFromOrderItem(item, model);
                return(model.PartInventory);
            }
        }