Exemplo n.º 1
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // Grouping the categories with products.
            if (this.PriceListView != null)
            {
                var categoryDictionary = new Dictionary <string, Dictionary <string, Dictionary <string, List <PriceListItemView> > > >();
                this.PriceListView.GroupBy(i => i.Category).Distinct().ToList().ForEach(i => categoryDictionary.Add(i.Key, new Dictionary <string, Dictionary <string, List <PriceListItemView> > >()));
                this.PriceListView.GroupBy(i => i.SubCategory).Distinct().ToList().ForEach(i =>
                {
                    var subCat = i.First();
                    categoryDictionary[subCat.Category].Add(i.Key, new Dictionary <string, List <PriceListItemView> >());
                });
                this.PriceListView.GroupBy(i => i.ProductName).Distinct().ToList().ForEach(i =>
                {
                    var productName = i.First();
                    categoryDictionary[productName.Category][productName.SubCategory].Add(i.Key, i.Select(item => item).ToList());
                });

                if (!string.IsNullOrEmpty(this.MultipleTax))
                {
                    var msg = this.GetLocalResourceObject("MultipleTaxMessage.Text") as string;
                    if (msg != null)
                    {
                        TaxInformation.Text = string.Format(msg, this.ShippingAndHandlingTax, DateTime.Now.ToShortDateString());
                    }
                }
                else if (!string.IsNullOrEmpty(this.SalesTax) && !string.IsNullOrEmpty(this.ShippingAndHandlingTax))
                {
                    var msg = this.GetLocalResourceObject("TaxInformation.Text") as string;
                    if (msg != null)
                    {
                        TaxInformation.Text = string.Format(msg, this.SalesTax, this.ShippingAndHandlingTax, DateTime.Now.ToShortDateString());
                    }
                }

                reCategory.DataSource = categoryDictionary;
                reCategory.DataBind();
            }

            // Header settings.
            lblTaxGeoInformation.Text = this.TaxGeoInformation;
            // Name now comes from Profile model.
            if (DistributorProfileModel != null)
            {
                lblDistributorName.Text = DistributorProfileModel.DistributorName();
            }

            btnSaveXLS.Visible = ExportXLS;
            btnPrint.Visible   = !ExportXLS;
        }
        /// <summary>
        /// The setup customer order data.
        /// </summary>
        /// <param name="customerOrderId">
        /// The customer order id.
        /// </param>
        /// <param name="distributorId"></param>
        /// <param name="countryCode"></param>
        /// <param name="locale"></param>
        /// <param name="isAddressValid"></param>
        /// <param name="customerAddressId"></param>
        public static void SetupCustomerOrderData(string customerOrderId, string distributorId, string countryCode, string locale, out bool isAddressValid, out int customerAddressId)
        {
            isAddressValid = false;
            var customerOrderV01 = CustomerOrderingProvider.GetCustomerOrderByOrderID(customerOrderId);

            // Close all carts for provided Customer Order ID
            if (customerOrderV01.OrderStatus == CustomerOrderStatusType.Cancelled)
            {
                ShoppingCartProvider.DeleteOldShoppingCartForCustomerOrder(
                    distributorId, customerOrderV01.OrderID);
            }

            var  existingCart                  = ShoppingCartProvider.GetShoppingCart(distributorId, locale);
            bool useAddressValidation          = ShippingProvider.GetShippingProvider(customerOrderV01.ProcessingCountry).AddressValidationRequired();
            bool useDsAddressAsShippingAddress = ShippingProvider.GetShippingProvider(customerOrderV01.ProcessingCountry).DSAddressAsShippingAddress();
            var  DShippingAddressForCustomer   = new List <DeliveryOption>();

            if (HLConfigManager.Configurations.PickupOrDeliveryConfiguration.SetDSAddressforCashOnDelivery && customerOrderV01.PaymentMethodChoice == CustomerPaymentMethodChoice.CashOnDelivery) // Mappinf object error CustomerPaymentMethodChoice.CashOnDelivery)
            {
                var dsProfile = DistributorOrderingProfileProvider.GetProfile(distributorId,
                                                                              customerOrderV01.ProcessingCountry);

                var mailingAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, distributorId, customerOrderV01.ProcessingCountry);
                if (string.IsNullOrWhiteSpace(mailingAddress.PostalCode) || string.IsNullOrWhiteSpace(mailingAddress.City) || string.IsNullOrWhiteSpace(mailingAddress.Line1) || string.IsNullOrWhiteSpace(mailingAddress.StateProvinceTerritory) || dsProfile.PhoneNumbers == null)
                {
                    HttpContext.Current.Response.Redirect("~/dswebadmin/customerorders.aspx?error=2", false);
                }
                useDsAddressAsShippingAddress = true;
                DShippingAddressForCustomer.Add(

                    new DeliveryOption
                {
                    Address     = ObjectMappingHelper.Instance.GetToShipping(mailingAddress),
                    Id          = -4,
                    AddressId   = new Guid(),
                    AddressType = "Shipping",
                    Alias       = "",
                    AltAreaCode = string.Empty,
                    AltPhone    = string.Empty,
                    AreaCode    = mailingAddress.PostalCode,
                    Recipient   = string.Empty,
                    PostalCode  = mailingAddress.PostalCode,
                    Phone       = dsProfile.PhoneNumbers != null
                                    ? dsProfile.PhoneNumbers.Find(x => x.IsPrimary) != null
                                          ? dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).CountryPrefix + dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).AreaCode + dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).Number
                                          : dsProfile.PhoneNumbers.FirstOrDefault().CountryPrefix + dsProfile.PhoneNumbers.FirstOrDefault().AreaCode + dsProfile.PhoneNumbers.FirstOrDefault().Number
                                    : string.Empty,
                    State       = mailingAddress.StateProvinceTerritory,
                    FreightCode = "NOF",         // DEFAULT FREIGHTCODE TO CALL retrieveFreightCode,
                    Name        = DistributorProfileModel.DistributorName(),
                }
                    );
            }
            int            temporaryEnteredAddressId = 0;
            DeliveryOption option           = null;
            var            custOrderAddress = GetCustomerAddress(customerOrderV01, useAddressValidation);

            if ((custOrderAddress != null) && (!useDsAddressAsShippingAddress))
            {
                ShippingProvider.GetShippingProvider(countryCode).GetShippingAddresses(
                    distributorId, customerOrderV01.ProcessingLocale);
                temporaryEnteredAddressId =
                    ShippingProvider.GetShippingProvider(countryCode).SaveShippingAddress(
                        distributorId, customerOrderV01.ProcessingLocale, custOrderAddress, true, true, false);

                isAddressValid = true;

                // Add address To Temporary Address and Insert customer order cart
                custOrderAddress.ID = temporaryEnteredAddressId;
                option = new DeliveryOption(custOrderAddress);
            }
            else
            {
                ShippingAddress_V02 shippingAddress = null;
                if (useDsAddressAsShippingAddress)
                {
                    List <DeliveryOption> shippingAddresses = DShippingAddressForCustomer.Count > 0 ? DShippingAddressForCustomer:
                                                              ShippingProvider.GetShippingProvider(countryCode).GetShippingAddresses(
                        distributorId, customerOrderV01.ProcessingLocale);
                    if (shippingAddresses != null && shippingAddresses.Count > 0)
                    {
                        if ((shippingAddress = shippingAddresses.Find(s => s.IsPrimary)) == null)
                        {
                            shippingAddress = shippingAddresses.First();
                        }
                    }
                }
                if (shippingAddress != null)
                {
                    ShippingAddress_V02 shippingAddressV2 = null;
                    if (DShippingAddressForCustomer.Count > 0)
                    {
                        shippingAddressV2           = DShippingAddressForCustomer[0];
                        shippingAddressV2.ID        = -4;
                        shippingAddressV2.Recipient = DistributorProfileModel.DistributorName();
                    }

                    option = new DeliveryOption(shippingAddress);
                    temporaryEnteredAddressId = DShippingAddressForCustomer.Count > 0 ?  ShippingProvider.GetShippingProvider(countryCode).SaveShippingAddress(
                        distributorId, customerOrderV01.ProcessingLocale, shippingAddressV2, true, true, false) : shippingAddress.ID;
                    if (DShippingAddressForCustomer.Count > 0)
                    {
                        DShippingAddressForCustomer[0].ID = temporaryEnteredAddressId;
                    }
                }
                else
                {
                    option = new DeliveryOption();
                }
            }

            customerAddressId = temporaryEnteredAddressId;

            if (existingCart != null)
            {
                if (existingCart.DeliveryInfo != null)
                {
                    existingCart.DeliveryInfo.Address.ID = temporaryEnteredAddressId;
                }
                ShoppingCartProvider.UpdateShoppingCart(existingCart);
            }
            else
            {
                var shippingInfo = new Shipping.ShippingInfo(ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping, option);

                MyHLShoppingCart customerCart = ShoppingCartProvider.InsertShoppingCart(
                    distributorId,
                    customerOrderV01.ProcessingLocale,
                    ServiceProvider.CatalogSvc.OrderCategoryType.RSO,
                    shippingInfo,
                    getCustomerOrderDetails(customerOrderV01), false, string.Empty);

                if (customerCart != null)
                {
                    foreach (ShoppingCartItem_V01 item in
                             GetCustomerCartItems(customerCart.ShoppingCartID, customerOrderV01.OrderItems))
                    {
                        ShoppingCartProvider.InsertShoppingCartItem(
                            distributorId, item, customerCart.ShoppingCartID);
                    }

                    // Update Status of Order To In Progress In Azure
                    CustomerOrderingProvider.UpdateCustomerOrderStatus(
                        customerOrderV01.OrderID, customerOrderV01.OrderStatus, CustomerOrderStatusType.InProgress);
                }
                else
                {
                    throw new Exception("Unable to Convert Customer Order To DO Order");
                }
            }
        }