示例#1
0
        public void Run()
        {
            var orderApiClient = new OrderAPISoapClient();

            var cred = new Credentials();

            cred.Username = Properties.Settings.Default.ByDesignApiUser;
            cred.Password = Properties.Settings.Default.ByDesignApiPassword;

            var responseOrderList = orderApiClient.GetOrderListRecent(
                cred,
                Properties.Settings.Default.Freedom_RecentPeriodType,
                Properties.Settings.Default.Freedom_RecentPeriodLength,
                false);

            using (var dbContext = new BiWellEntities())
            {
                dbContext.Database.Log = s => Debug.WriteLine(s);

                foreach (var order in responseOrderList)
                {
                    var dbOrder = dbContext.order_table.Find(order.OrderID);
                    if (dbOrder == null)
                    {
                        var responseOrderInfo = orderApiClient.GetOrderInfo_V2(cred, order.OrderID);
                        if (responseOrderInfo.Success == 0)
                        {
                            throw new InvalidOperationException(responseOrderInfo.Message);
                        }

                        dbOrder = new order_table
                        {
                            order_id           = order.OrderID,
                            created_at         = order.CreatedDate,
                            modified_at        = order.LastModifiedDate,
                            status             = responseOrderInfo.Status,
                            shipping_method_id = responseOrderInfo.ShipMethodID
                        };

                        if (dbOrder.modified_at == DateTime.MinValue)
                        {
                            dbOrder.modified_at = null;
                        }

                        dbContext.order_table.Add(dbOrder);
                    }
                }

                dbContext.SaveChanges();
            }
        }
示例#2
0
        private void FillItemWeights(DeliveryParameters deliveryParameters)
        {
            BiWellEntities db = new BiWellEntities();

            foreach (var item in deliveryParameters.Items)
            {
                var itemWeight = db.ItemWeights.Find(item.ItemId);
                if (itemWeight == null)
                {
                    throw new InvalidOperationException($"Весовая характеристика не найдена для {item.ItemId}: {item.Name}");
                }

                item.Weight = itemWeight.Weight;
            }
        }
示例#3
0
        private List <DeliveryParameters> ReadOrdersToDeliveryEx()
        {
            //Stopwatch stopWatch = new Stopwatch();
            //stopWatch.Start();

            var result = new List <DeliveryParameters>();

            using (var context = new BiWellEntities())
            {
                context.Database.Log = s => Debug.WriteLine(s);

                //var dateFrom = DateTime.Today.AddDays(-Properties.Settings.Default.Freedom_RecentPeriodLength);

                var dbOrders = context.order_table
                               .Where(o => o.status == "Posted")
                               .Where(o => o.shipping_method_id != null)
                               .Where(o => o.shipping_method_id != Properties.Settings.Default.Freedom_SelfPickupShipMethodId)
                               .OrderByDescending(o => o.modified_at)
                               .Take(Properties.Settings.Default.BiWell_OrdersToDeliveryCount);

                foreach (var dbOrder in dbOrders)
                {
                    var orderToDelivery = new DeliveryParameters
                    {
                        OrderId    = dbOrder.order_id,
                        CreatedAt  = dbOrder.created_at,
                        ModifiedAt = dbOrder.modified_at
                    };

                    orderToDelivery.Status       = dbOrder.status;
                    orderToDelivery.ShipMethodId = dbOrder.shipping_method_id.Value;
                    orderToDelivery.ShipMethod   = context.shipping_method.FirstOrDefault(m => m.id == dbOrder.shipping_method_id.Value)?.description;

                    FillFromFreedomDetails(orderToDelivery);
                    FillItemWeights(orderToDelivery);

                    result.Add(orderToDelivery);
                }
            }

            //stopWatch.Stop();
            //TimeSpan ts = stopWatch.Elapsed;

            return(result);
        }
示例#4
0
        public void Run()
        {
            var orderApiClient = new OrderAPISoapClient();

            var cred = new Credentials();

            cred.Username = Properties.Settings.Default.ByDesignApiUser;
            cred.Password = Properties.Settings.Default.ByDesignApiPassword;

            var responseShippingMethods = orderApiClient.GetShippingMethods(cred);

            using (var dbContext = new BiWellEntities())
            {
                dbContext.Database.Log = s => Debug.WriteLine(s);

                foreach (var sm in responseShippingMethods)
                {
                    var dbShippingMethod = dbContext.shipping_method.Find(sm.ID);
                    if (dbShippingMethod != null)
                    {
                        dbShippingMethod.description = sm.Description;
                    }
                    else
                    {
                        dbShippingMethod = new shipping_method
                        {
                            id          = sm.ID,
                            description = sm.Description
                        };

                        dbContext.shipping_method.Add(dbShippingMethod);
                    }
                }

                dbContext.SaveChanges();
            }
        }
示例#5
0
        public void ProcessNotification(PaymentNotificationData data)
        {
            try
            {
                int orderId = 0;
                if (int.TryParse(data.mnt_transaction_id, out orderId))
                {
                    var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
                    var orderApiCred   = orderApiClient.CreateCredentials();
                    var response       = orderApiClient.GetOrderInfo_V2(orderApiCred, orderId);

                    if (response.Success > 0)
                    {
                        int custNum = 0;
                        if (int.TryParse(response.CustomerNumber, out custNum))
                        {
                            if (custNum >= 2000)
                            {
                                var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiCred, orderId);
                                if (orderDetailsResponse.Success == 0)
                                {
                                    throw new InvalidOperationException(orderDetailsResponse.Message);
                                }

                                if (orderDetailsResponse.OrderDetailsResponse
                                    .Any(x => x.ProductID.Equals(Properties.Settings.Default.Freedom_VipKitItemId)))
                                {
                                    // change customer type
                                    var onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient();
                                    var onlineApiCred   = onlineApiClient.CreateCredentials();

                                    var types         = onlineApiClient.GetCustomerTypes(onlineApiCred);
                                    var preferredType = types.FirstOrDefault(x => x.Abbreviation.Equals(CustomerType_Preferred));
                                    if (preferredType != null)
                                    {
                                        onlineApiClient.SetCustomerType(onlineApiCred, response.CustomerNumber, preferredType.ID);
                                    }
                                }
                            }
                        }

                        OrderStatus currentStatus = OrderStatus.Unknown;
                        if (Enum.TryParse(response.Status, out currentStatus))
                        {
                            if (currentStatus == OrderStatus.Entered)
                            {
                                orderApiClient.SetStatusPosted(orderApiCred, orderId, 0);

                                using (BiWellEntities context = new BiWellEntities())
                                {
                                    order_payment payment = new order_payment
                                    {
                                        order_id   = orderId,
                                        amount     = decimal.Parse(data.mnt_amount, CultureInfo.InvariantCulture),
                                        created_at = DateTime.UtcNow
                                    };

                                    context.order_payment.Add(payment);
                                    context.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _looger.Log(ex.Message);
            }
        }