public List<MyHLShoppingCartView> GetOrdersWithDetail(string distributorId, int customerProfileID, string countryCode, DateTime startOrderDate, DateTime endOrderDate, MyHerbalife3.Ordering.Providers.China.OrderStatusFilterType statusFilter, string filterExpressions, string sortExpressions, bool isNonGDOOrder = false, bool isPreOrdering = false, string orderNumber = null) { List<MyHLShoppingCartView> result; List<OnlineOrder> orderListing = null; List<OrderStatusType> ordStsList = new List<OrderStatusType>(); List<PaymentGatewayRecordStatusType> pgrStsList = new List<PaymentGatewayRecordStatusType>(); List<PaymentPendingOrderPaymentStatusType> ppoStsList = new List<PaymentPendingOrderPaymentStatusType>(); if (Settings.GetRequiredAppSetting("GetOrderinfoCache", "true") == "true") { result = SearchFromCachedList(distributorId, statusFilter, filterExpressions, sortExpressions, startOrderDate, endOrderDate, orderNumber); if (result != null) { return result; } } result = new List<MyHLShoppingCartView>(); switch (statusFilter) { case OrderStatusFilterType.Cancel_Order: ordStsList.Add(OrderStatusType.Cancel_Order); break; case OrderStatusFilterType.Complete: ordStsList.Add(OrderStatusType.Complete); break; case OrderStatusFilterType.In_Progress: ordStsList.Add(OrderStatusType.In_Progress); break; case OrderStatusFilterType.NTS_Printed: ordStsList.Add(OrderStatusType.NTS_Printed); break; case OrderStatusFilterType.To_Be_Assign: ordStsList.Add(OrderStatusType.To_Be_Assign); break; case OrderStatusFilterType.Payment_Failed: case OrderStatusFilterType.Payment_Pending: ordStsList = null; break; } switch (statusFilter) { case OrderStatusFilterType.Payment_Pending: pgrStsList.Add(PaymentGatewayRecordStatusType.Unknown); break; case OrderStatusFilterType.Cancel_Order: pgrStsList.Add(PaymentGatewayRecordStatusType.CancelledByUser); break; case OrderStatusFilterType.Payment_Failed: pgrStsList.Add(PaymentGatewayRecordStatusType.Declined); break; case OrderStatusFilterType.All: pgrStsList.Add(PaymentGatewayRecordStatusType.Unknown); pgrStsList.Add(PaymentGatewayRecordStatusType.CancelledByUser); pgrStsList.Add(PaymentGatewayRecordStatusType.Declined); break; } switch (statusFilter) { case OrderStatusFilterType.Cancel_Order: ppoStsList.Add(PaymentPendingOrderPaymentStatusType.CNCancelled); break; case OrderStatusFilterType.Payment_Pending: ppoStsList.Add(PaymentPendingOrderPaymentStatusType.CNPending); break; case OrderStatusFilterType.All: ppoStsList.Add(PaymentPendingOrderPaymentStatusType.CNCancelled); ppoStsList.Add(PaymentPendingOrderPaymentStatusType.CNPending); break; } var req = new GetOrdersRequest_V02 { CountryCode = countryCode, CustomerProfileID = customerProfileID, OrderFilter = new OrdersFilter { DistributorId = distributorId, StartDate = startOrderDate, EndDate = endOrderDate, OrderStatusList = ordStsList, IsNonGDOOrders = isNonGDOOrder, OrderNumber = orderNumber, }, OrderingType = isPreOrdering ? OrderingType.PreOrder : OrderingType.RSO, PaymentGatewayRecordStatusList = pgrStsList, PaymentPendingOrderPaymentStatusList = ppoStsList, }; if (_chinaOrderProxy == null) _chinaOrderProxy = ServiceClientProvider.GetChinaOrderServiceProxy(); var rsp = _chinaOrderProxy.GetOrdersWithDetail(new GetOrdersWithDetailRequest(req)).GetOrdersWithDetailResult as GetOrdersResponse_V01; if (Helper.Instance.ValidateResponse(rsp)) { orderListing = rsp.Orders; } else LoggerHelper.Error(string.Format("MyHLShoppingCartView.GetOrdersWithDetail() Error. Unsuccessful result from web service ChinaOrderSVC.GetOrdersWithDetail. Data: DistributorId={0}", distributorId)); bool copyEnabled = true; bool hasUnknownOrder = false; bool pendingPayment = false; List<MyHLProductItemView> cartItems; if (Helper.Instance.HasData(orderListing)) { var unknownOrder = (from a in orderListing where a.Status == "未知" select a).FirstOrDefault(); //dont display feedback, if any order is pending if (unknownOrder != null) { hasUnknownOrder = true; } var virtualProduct = GetVirtualProduct(); foreach (var order in orderListing) { var priceInfo = order.Pricing as OrderTotals_V01; var priceInfo_V02 = order.Pricing as OrderTotals_V02; if (priceInfo == null) continue; switch (order.Status) { case "未知": //unknown order copyEnabled = false; pendingPayment = true; break; default: pendingPayment = false; copyEnabled = !hasUnknownOrder; break; } var orderView = new MyHLShoppingCartView { ID = order.ShoppingCartID.ToString(), OrderNumber = order.OrderID ?? string.Empty, Date = order.ReceivedDate.ToString("d", CultureInfo.CurrentCulture), DateTimeForOrder = order.ReceivedDate, VolumePoints = priceInfo.VolumePoints.ToString("00.00"), TotalAmountValue = priceInfo.AmountDue, VolumePointsValue = priceInfo.VolumePoints, ProductTaxTotal = priceInfo_V02 != null ? priceInfo_V02.ProductTaxTotal : decimal.Zero, DonationAmount = priceInfo_V02 != null ? priceInfo_V02.Donation : decimal.Zero, SelfDonationAmount = priceInfo_V02 != null ? priceInfo_V02.SelfDonationAmount : decimal.Zero, OnBehalfDonationAmount = priceInfo_V02 != null ? priceInfo_V02.OnBehalfDonationAmount : decimal.Zero, OnBehalfDonationContact = priceInfo_V02 != null ? priceInfo_V02.OnBehalfDonationContact : string.Empty, SelfDonationMemberId = priceInfo_V02 != null ? priceInfo_V02.SelfDonationMemberId : string.Empty, OnBehalfDonationName = priceInfo_V02 != null ? priceInfo_V02.OnBehalfDonationName : string.Empty, DiscountAmount = priceInfo_V02 != null ? priceInfo_V02.DiscountAmount : decimal.Zero, FreightCharges = priceInfo_V02 != null && null != priceInfo_V02.ChargeList && priceInfo_V02.ChargeList.Any() ? GetFreightCharges(priceInfo_V02.ChargeList) : decimal.Zero, OrderStatus = order.Status, StoreInfo = order.StoreInfo, WarehouseCode = ((order.Shipment as ShippingInfo_V01) == null) ? "" : (order.Shipment as ShippingInfo_V01).WarehouseCode, ChannelInfo = order.ChannelInfo, OrderMonth = order.OrderMonth, IsCopyEnabled = order.ShoppingCartID > 0 ? copyEnabled : false, //If ShoppingCartID is 0 then CopyEnabled is set to false OrderHeaderId = order.OrderHeaderID, DistributorID = distributorId, HasFeedBack = (order.HasFeedBack && !hasUnknownOrder), CreatedBy = order.CreatedBy, IsPaymentPending = pendingPayment, }; var shippingAddress = order.Shipment as ShippingInfo_V01; if (shippingAddress != null) { if (shippingAddress.Address != null) orderView.Address = shippingAddress.Address.StateProvinceTerritory + shippingAddress.Address.CountyDistrict + shippingAddress.Address.City + shippingAddress.Address.Line1 + shippingAddress.Address.PostalCode; orderView.AddressValue = ObjectMappingHelper.Instance.GetToShipping(shippingAddress.Address); orderView.Recipient = shippingAddress.Recipient; orderView.Phone = shippingAddress.Phone; orderView.ShippingMethodId = shippingAddress.ShippingMethodID; } orderView.TotalAmount = (priceInfo.AmountDue + orderView.FreightCharges).ToString("00"); var createdBy = order.CreatedBy; if (!string.IsNullOrWhiteSpace(createdBy)) orderView.IsHistoricalData = (createdBy.Trim().ToUpper() != "GDO"); cartItems = new List<MyHLProductItemView>(); if (order.OrderItems != null && order.OrderItems.Count > 0) { foreach (var itm in order.OrderItems) { if (string.IsNullOrEmpty(itm.SKU)) continue; if (itm.SKU.EndsWith("||")) { itm.SKU = itm.SKU.Replace("||", ""); //a workaround to indicate this is preordering. orderView.IsCopyEnabled = false; } if (itm is OnlineOrderItem) { var orderItem = itm as OnlineOrderItem; if (orderItem != null) { cartItems.Add(new MyHLProductItemView() { Quantity = orderItem.Quantity, SKU = string.IsNullOrEmpty(orderItem.SKU) ? "" : orderItem.SKU.Trim(), Description = orderItem.Description, RetailPrice = orderItem.RetailPrice }); } } else if (itm is OrderItem_V02) { var orderItem = itm as OrderItem_V02; if (orderItem != null) { cartItems.Add(new MyHLProductItemView() { Quantity = orderItem.Quantity, SKU = string.IsNullOrEmpty(orderItem.SKU) ? "" : orderItem.SKU.Trim(), Description = orderItem.Description, RetailPrice = orderItem.RetailPrice }); } } } } orderView.CartItems = cartItems; if (IsChina) { var isAllVirtualOrder = IsAllVirtualOrder(orderView, virtualProduct); orderView.IsCopyEnabled = isAllVirtualOrder ? false : orderView.IsCopyEnabled; if (isAllVirtualOrder) { orderView.HasFeedBack = true; //Set this true so that the feedback button will not showing. } } result.Add(orderView); } } // Search if (!string.IsNullOrWhiteSpace(filterExpressions)) result = Search(result, filterExpressions); // Order Number if (!string.IsNullOrWhiteSpace(orderNumber)) result = Search(result, orderNumber); // Sort if (string.IsNullOrWhiteSpace(sortExpressions)) result = result.OrderByDescending(item => item.DateTimeForOrder).ToList(); else result = ChinaDoSortBy(result, sortExpressions); if (Settings.GetRequiredAppSetting("GetOrderinfoCache", "true") == "true") { string cacheKey = string.Format(OrderListCaheKey + distributorId + "CN" + statusFilter + filterExpressions + sortExpressions + startOrderDate.ToString(YearMonthDayFormat) + endOrderDate.ToString(YearMonthDayFormat) + orderNumber); HttpRuntime.Cache.Insert(cacheKey, result, null, DateTime.Now.AddMinutes(Convert.ToDouble(Settings.GetRequiredAppSetting("GetOrderinfoCacheTimeout"))), Cache.NoSlidingExpiration, CacheItemPriority.Low, null); } return result; }
private List<MyHLShoppingCartView> SearchFromCachedList(string distributorId, MyHerbalife3.Ordering.Providers.China.OrderStatusFilterType statusFilter, string filterExpressions, string sortExpressions, DateTime startOrderDate, DateTime endOrderDate, string orderNumber) { List<MyHLShoppingCartView> result = null; string cacheKey = string.Format(OrderListCaheKey + distributorId + "CN" + statusFilter + startOrderDate.ToString(YearMonthDayFormat) + endOrderDate.ToString(YearMonthDayFormat)); //search from general key first. if (Settings.GetRequiredAppSetting("GetOrderinfoCache", "true") == "true") { result = HttpRuntime.Cache[cacheKey] as List<MyHLShoppingCartView>; if (result != null) { // Search if (!string.IsNullOrWhiteSpace(filterExpressions)) result = Search(result, filterExpressions); // Order Number if (!string.IsNullOrWhiteSpace(orderNumber)) result = Search(result, orderNumber); // Sort if (string.IsNullOrWhiteSpace(sortExpressions)) result = result.OrderByDescending(item => item.DateTimeForOrder).ToList(); else result = ChinaDoSortBy(result, sortExpressions); } else { cacheKey = string.Format(OrderListCaheKey + distributorId + "CN" + statusFilter + filterExpressions + sortExpressions + startOrderDate.ToString(YearMonthDayFormat) + endOrderDate.ToString(YearMonthDayFormat) + orderNumber); result = HttpRuntime.Cache[cacheKey] as List<MyHLShoppingCartView>; } } return result; }