Exemple #1
0
        private List <OrderViewModel> GetOrderViewModelsFromDictionary(
            Dictionary <int, List <MyHLShoppingCartView> > orderList, string locale)
        {
            var orderViewModels = new List <OrderViewModel>();

            if (null == orderList && !orderList.Any())
            {
                return(orderViewModels);
            }

            foreach (var orders in orderList.Values.Where(orders => null != orders && orders.Any()))
            {
                orderViewModels.AddRange(
                    orders.Select(
                        shoppingCartView =>
                        ModelConverter.ConvertShoppingCartViewToOrderViewModel(shoppingCartView, locale)));
            }
            return(orderViewModels);
        }
Exemple #2
0
        public List <OrderViewModel> GetOrders(OrderSearchParameter request)
        {
            List <OrderViewModel> result = null;

            #region validation

            if (string.IsNullOrWhiteSpace(request.Locale) || string.IsNullOrWhiteSpace(request.MemberId))
            {
                return(result);
            }

            #endregion

            var countryCode = request.Locale.Substring(3, 2);
            var localNow    = DateUtils.GetCurrentLocalTime(countryCode);

            var defaultStartDate = localNow.AddMonths(-12);
            var defaultEndDate   = localNow;

            DateTime startDate = request.From ?? defaultStartDate;
            DateTime endDate   = request.To ?? defaultEndDate;

            if (!string.IsNullOrEmpty(request.OrderNumber))
            {
                var orderViewmodelsByOrderNumber = new List <OrderViewModel>();
                var orders = GetOrdersByOrderNumber(request.MemberId, request.Locale, request.OrderNumber, startDate,
                                                    endDate);
                var addressGuid = Guid.Empty;
                var country     = string.Empty;
                if (null != orders && orders.Any())
                {
                    if (orders.Count == 1)
                    {
                        var mobileQuoteHelper = new MobileQuoteHelper();
                        var shoppingCart      = mobileQuoteHelper.GetShoppingCart(request.OrderNumber, Guid.Empty);
                        if (null != shoppingCart && shoppingCart.DeliveryOption == DeliveryOptionType.Shipping)
                        {
                            var addressId = shoppingCart.ShippingAddressID;
                            if (addressId > 0)
                            {
                                var shippingProvider =
                                    ShippingProvider.GetShippingProvider(countryCode);
                                if (null != shippingProvider)
                                {
                                    var address = shippingProvider.GetShippingAddressFromAddressGuidOrId(Guid.Empty,
                                                                                                         addressId);
                                    addressGuid = null != address ? address.AddressId : Guid.Empty;
                                    country     = null != address && null != address.Address
                                        ? address.Address.Country
                                        : string.Empty;
                                }
                            }
                        }
                    }
                    orderViewmodelsByOrderNumber.AddRange(
                        orders.Select(
                            item => ModelConverter.ConvertShoppingCartViewToOrderViewModel(item, request.Locale)));
                    if (addressGuid != Guid.Empty && null != orderViewmodelsByOrderNumber &&
                        orderViewmodelsByOrderNumber.Any() && orderViewmodelsByOrderNumber.Count == 1 &&
                        null != orderViewmodelsByOrderNumber[0].Shipping &&
                        null != orderViewmodelsByOrderNumber[0].Shipping.Address)
                    {
                        orderViewmodelsByOrderNumber[0].Shipping.Address.CloudId = addressGuid;
                        orderViewmodelsByOrderNumber[0].Shipping.Address.Country = country;
                        if (request.Locale == "zh-CN")
                        {
                            orderViewmodelsByOrderNumber[0].Shipping.FreightVariant =
                                GetFreightVariant(orderViewmodelsByOrderNumber[0].Shipping.DeliveryType);
                        }
                    }
                }
                return(orderViewmodelsByOrderNumber);
            }
            List <MyHLShoppingCartView> orderList;
            var shoppingCartView  = new MyHLShoppingCartView();
            var customerProfileId =
                DistributorOrderingProfileProvider.GetProfile(request.MemberId, countryCode).CNCustomorProfileID;

            //var proposedStartDate = DateTime.Now.AddMonths(-6);
            //DateTime startDate = new DateTime(proposedStartDate.Year, proposedStartDate.Month, proposedStartDate.Day); //ensure the time is the start of the day, which is 00:00:00
            //DateTime endDate = DateTime.Now;

            orderList = shoppingCartView.GetOrdersWithDetail(request.MemberId, customerProfileId, request.Locale,
                                                             startDate, endDate, OrderStatusFilterType.All, "", "");

            if (orderList != null)
            {
                if (request.PageSize > 0 && orderList.Any())
                {
                    var paged = orderList.Skip((request.PageNumber) * request.PageSize).Take(request.PageSize);
                    if (null != paged && paged.Any())
                    {
                        orderList = paged.ToList();
                    }
                    else
                    {
                        orderList = new List <MyHLShoppingCartView>();
                    }
                }

                result = new List <OrderViewModel>();

                foreach (var itm in orderList)
                {
                    var newItem = ModelConverter.ConvertShoppingCartViewToOrderViewModel(itm, request.Locale);
                    result.Add(newItem);
                }
            }

            return(result);
        }