Ejemplo n.º 1
0
        public int Save(ref AddressViewModel address, string memberId, string locale)
        {
            var shippingProvider = ShippingProvider.GetShippingProvider(locale.Substring(3));

            if (shippingProvider != null)
            {
                //check if the address exist
                var addressToSave = ModelConverter.ConvertAddressViewModelToShippingAddress(address);
                if (locale == "zh-CN")
                {
                    addressToSave.Address.Line3 = string.Empty;
                    addressToSave.Address.Line4 = string.Empty;
                }
                var existing = shippingProvider.GetShippingAddressFromAddressGuidOrId(address.CloudId, 0);
                if (null != existing)
                {
                    addressToSave.ID = existing.ID;
                }
                var shippingAddressId = shippingProvider.SaveShippingAddress(memberId, locale, addressToSave, false, true, false);
                if (shippingAddressId > 0)
                {
                    var savedAddress = shippingProvider.GetShippingAddressFromAddressGuidOrId(address.CloudId, 0);
                    address.LastUpdatedDate = savedAddress.Created;
                    address = ModelConverter.ConvertShippingAddressToAddressViewModel(savedAddress);
                    address.CustomShippingMethods = ModelConverter.GetCustomShippingMethods(memberId, savedAddress,
                                                                                            locale);
                }
                return(shippingAddressId);
            }
            return(0);
        }
Ejemplo n.º 2
0
        public OrderSummaryResponseViewModel GetOrderList(OrderSummaryRequestViewModel request)
        {
            #region validation

            if (request == null)
            {
                return(null);
            }

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

            #endregion

            var response = new OrderSummaryResponseViewModel
            {
                Pending   = null,
                Completed = null,
                Failed    = null
            };

            if (request.Limit == 0)
            {
                //Set default to 5
                request.Limit = 5;
            }
            var result = GetOrderList(request.MemberId, request.Locale, request.From, request.To);
            response = ModelConverter.ConvertMyHLSCListToOrderSummaryResponse(result, request.Limit, request.Locale);
            return(response);
        }
Ejemplo n.º 3
0
        public List <AddressViewModel> Get(GetAddressRequestViewModel request)
        {
            var shippingProvider = ShippingProvider.GetShippingProvider(request.Locale.Substring(3));
            var result           = new List <AddressViewModel>();

            if (shippingProvider != null)
            {
                var shippingAddresses = shippingProvider.GetShippingAddresses(request.MemberId, request.Locale);
                //filter the addresses
                if (request.From != null)
                {
                    shippingAddresses = shippingAddresses.Where(x => x.Created >= request.From).ToList();
                }
                if (request.To != null)
                {
                    shippingAddresses = shippingAddresses.Where(x => x.Created <= request.To).ToList();
                }
                if (shippingAddresses != null && shippingAddresses.Any())
                {
                    result.AddRange(
                        shippingAddresses.Select(
                            a => ModelConverter.ConvertAddressToViewModel(a, false, request.MemberId, request.Locale)));
                }
            }
            return(result);
        }
        public List <ExpressTrackingInfoViewModel> Get(OrderTrackingRequestViewModel request)
        {
            var expressInfo = China.OrderProvider.GetExpressTrackInfo(request.OrderId);

            if (null == expressInfo)
            {
                return(null);
            }
            var expressInfoDetail = China.OrderProvider.GetExternalExpressTrackInfo(expressInfo.ExpressCode,
                                                                                    expressInfo.ExpressNum);

            return(ModelConverter.ConvertExpresInfoToViewModel(expressInfo, expressInfoDetail));
        }
Ejemplo n.º 5
0
        public List <CustomShippingMethodViewModel> GetShippingMethods(string memberId, Guid id, string locale)
        {
            var shippingProvider = ShippingProvider.GetShippingProvider(locale.Substring(3));

            if (shippingProvider != null)
            {
                var existing = shippingProvider.GetShippingAddressFromAddressGuidOrId(id, 0);
                if (existing != null)
                {
                    return(ModelConverter.GetCustomShippingMethods(memberId, existing, locale));
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
        public AddressViewModel Delete(string memberId, Guid id, string locale)
        {
            var shippingProvider = ShippingProvider.GetShippingProvider(locale.Substring(3));

            if (shippingProvider != null)
            {
                var existing = shippingProvider.GetShippingAddressFromAddressGuidOrId(id, 0);
                if (existing != null)
                {
                    shippingProvider.DeleteShippingAddress(memberId, locale, existing);
                    return(ModelConverter.ConvertShippingAddressToAddressViewModel(existing));
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
        public List <AddressViewModel> Get(string memberId, string locale)
        {
            var shippingProvider = ShippingProvider.GetShippingProvider(locale.Substring(3));
            var result           = new List <AddressViewModel>();

            if (shippingProvider != null)
            {
                var shippingAddresses = shippingProvider.GetShippingAddresses(memberId, locale);
                if (shippingAddresses != null && shippingAddresses.Any())
                {
                    result.AddRange(
                        shippingAddresses.Select(
                            a => ModelConverter.ConvertAddressToViewModel(a, true, memberId, locale)));
                }
            }
            return(result);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public List <PickupViewModel> GetSavedDeliveryOptions(string memberId, string locale)
        {
            var shippingProvider = ShippingProvider.GetShippingProvider(locale.Substring(3));
            var result           = new List <PickupViewModel>();

            if (null != shippingProvider)
            {
                var list      = shippingProvider.GetPickupLocationsPreferences(memberId, locale.Substring(3));
                var puOptions = shippingProvider.GetDeliveryOptions(DeliveryOptionType.PickupFromCourier, new ShippingAddress_V01()
                {
                    Address = new Address_V01()
                    {
                        Country = locale.Substring(3)
                    }
                });
                if (null != list && list.Any())
                {
                    //convert and fill info
                    result.AddRange(list.Select(location => ModelConverter.ConvertDeliveryOptionToViewModel(location, puOptions)));
                }
                return(result);
            }
            return(null);
        }
Ejemplo n.º 10
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);
        }