public ActionResult Configure()
        {
            var model = new USPSShippingModel();

            model.Url      = _uspsSettings.Url;
            model.Username = _uspsSettings.Username;
            model.Password = _uspsSettings.Password;
            model.AdditionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge;



            // Load Domestic service names
            string carrierServicesOfferedDomestic = _uspsSettings.CarrierServicesOfferedDomestic;

            foreach (string service in USPSServices.DomesticServices)
            {
                model.AvailableCarrierServicesDomestic.Add(service);
            }

            if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic))
            {
                foreach (string service in USPSServices.DomesticServices)
                {
                    string serviceId = USPSServices.GetServiceIdDomestic(service);
                    if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOfferedDomestic))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        if (carrierServicesOfferedDomestic.Contains(String.Format("[{0}]", serviceId)))
                        {
                            model.CarrierServicesOfferedDomestic.Add(service);
                        }
                    }
                }
            }

            // Load Internation service names
            string carrierServicesOfferedInternational = _uspsSettings.CarrierServicesOfferedInternational;

            foreach (string service in USPSServices.InternationalServices)
            {
                model.AvailableCarrierServicesInternational.Add(service);
            }

            if (!String.IsNullOrEmpty(carrierServicesOfferedInternational))
            {
                foreach (string service in USPSServices.InternationalServices)
                {
                    string serviceId = USPSServices.GetServiceIdInternational(service);
                    if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOfferedInternational))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        if (carrierServicesOfferedInternational.Contains(String.Format("[{0}]", serviceId)))
                        {
                            model.CarrierServicesOfferedInternational.Add(service);
                        }
                    }
                }
            }
            return(View("~/Plugins/Shipping.USPS/Views/ShippingUSPS/Configure.cshtml", model));
        }
        public ActionResult Configure()
        {
            var model = new USPSShippingModel {
                Url      = _uspsSettings.Url,
                Username = _uspsSettings.Username,
                Password = _uspsSettings.Password,
                AdditionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge,
                ZipPostalCodeFrom        = _uspsSettings.ZipPostalCodeFrom,
                MinimumShippingCharge    = _uspsSettings.MinimumShippingCharge,
                InsuranceEnabled         = _uspsSettings.InsuranceEnabled
            };

            LoadBaseDomesticServices(model);
            LoadBaseInternationalServices(model);

            // Need to have a valid USPS login here
            if (!string.IsNullOrWhiteSpace(_uspsSettings.Username) && !string.IsNullOrWhiteSpace(_uspsSettings.Password))
            {
                try {
                    LoadDomesticServices(model);
                    LoadInternationalServices(model);
                } catch (Exception) {
                    ModelState.AddModelError(string.Empty, "Please enter valid USPS API credentials.");
                }
            }

            model.PluginVersion = GetPluginVersion();

            // ReSharper disable once Mvc.ViewNotResolved
            return(View("~/Plugins/Shipping.SeeSharpShipUsps/Views/ShippingSeeSharpShipUsps/Configure.cshtml", model));
        }
        public ActionResult Configure(USPSShippingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _uspsSettings.Url      = model.Url;
            _uspsSettings.Username = model.Username;
            _uspsSettings.Password = model.Password;
            _uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge;
            _uspsSettings.ZipPostalCodeFrom        = model.ZipPostalCodeFrom;
            _uspsSettings.MinimumShippingCharge    = model.MinimumShippingCharge;
            _uspsSettings.InsuranceEnabled         = model.InsuranceEnabled;

            if (model.CheckedBaseDomesticServices != null)
            {
                _uspsSettings.BaseDomesticServicesSelected = model.CheckedBaseDomesticServices.Aggregate((a, b) => $"{a},{b}");
            }

            if (model.CheckedDomesticServices != null)
            {
                _uspsSettings.DomesticServicesSelected = model.CheckedDomesticServices.Aggregate((a, b) => $"{a},{b}");
            }

            if (model.CheckedBaseInternationalServices != null)
            {
                _uspsSettings.BaseInternationalServicesSelected = model.CheckedBaseInternationalServices.Aggregate((a, b) => $"{a},{b}");
            }

            if (model.CheckedInternationalServices != null)
            {
                _uspsSettings.InternationalServicesSelected = model.CheckedInternationalServices.Aggregate((a, b) => $"{a},{b}");
            }

            _settingService.SaveSetting(_uspsSettings);

            return(Configure());
        }
        private void LoadBaseInternationalServices(USPSShippingModel model)
        {
            List <MailType> availableServices = EnumHelper.ToEnumerable <MailType>().ToList();

            foreach (MailType service in availableServices)
            {
                model.BaseInternationalServices.Add(new USPSSelectableService {
                    Id   = (int)service,
                    Name = service.ToString()
                });
            }

            string enabledServicesCsv = _uspsSettings.BaseInternationalServicesSelected;

            if (string.IsNullOrWhiteSpace(enabledServicesCsv))
            {
                return;
            }

            enabledServicesCsv = ClearSavedLegacyServices(enabledServicesCsv);
            SelectEnabledServices(enabledServicesCsv, model.BaseInternationalServices);
        }
        private void LoadDomesticServices(USPSShippingModel model)
        {
            IEnumerable <ServiceInfo> availableServices = _rateService.DomesticServices(_uspsSettings.Username, _uspsSettings.Password, _uspsSettings.ZipPostalCodeFrom);

            foreach (ServiceInfo service in availableServices)
            {
                model.DomesticServices.Add(new USPSSelectableService {
                    Id   = int.Parse(service.Id),
                    Name = GetModifiedServiceName(service.FullName)
                });
            }

            string enabledServicesCsv = _uspsSettings.DomesticServicesSelected;

            if (string.IsNullOrWhiteSpace(enabledServicesCsv))
            {
                return;
            }

            enabledServicesCsv = ClearSavedLegacyServices(enabledServicesCsv);
            SelectEnabledServices(enabledServicesCsv, model.DomesticServices);
        }
Example #6
0
        public ActionResult Configure(USPSShippingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _uspsSettings.Url      = model.Url;
            _uspsSettings.Username = model.Username;
            _uspsSettings.Password = model.Password;
            _uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge;



            // Save selected Domestic services
            var carrierServicesOfferedDomestic       = new StringBuilder();
            int carrierServicesDomesticSelectedCount = 0;

            if (model.CheckedCarrierServicesDomestic != null)
            {
                foreach (var cs in model.CheckedCarrierServicesDomestic)
                {
                    carrierServicesDomesticSelectedCount++;

                    string serviceId = USPSServices.GetServiceIdDomestic(cs);
                    //unselect any other services if NONE is selected
                    if (serviceId.Equals("NONE"))
                    {
                        carrierServicesOfferedDomestic.Clear();
                        carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId);
                        break;
                    }

                    if (!String.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId);
                    }
                }
            }
            // Add default options if no services were selected
            if (carrierServicesDomesticSelectedCount == 0)
            {
                _uspsSettings.CarrierServicesOfferedDomestic = "[1]:[3]:[4]:";
            }
            else
            {
                _uspsSettings.CarrierServicesOfferedDomestic = carrierServicesOfferedDomestic.ToString();
            }



            // Save selected International services
            var carrierServicesOfferedInternational       = new StringBuilder();
            int carrierServicesInternationalSelectedCount = 0;

            if (model.CheckedCarrierServicesInternational != null)
            {
                foreach (var cs in model.CheckedCarrierServicesInternational)
                {
                    carrierServicesInternationalSelectedCount++;
                    string serviceId = USPSServices.GetServiceIdInternational(cs);
                    // unselect other services if NONE is selected
                    if (serviceId.Equals("NONE"))
                    {
                        carrierServicesOfferedInternational.Clear();
                        carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId);
                        break;
                    }
                    if (!String.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId);
                    }
                }
            }
            // Add default options if no services were selected
            if (carrierServicesInternationalSelectedCount == 0)
            {
                _uspsSettings.CarrierServicesOfferedInternational = "[2]:[15]:[1]:";
            }
            else
            {
                _uspsSettings.CarrierServicesOfferedInternational = carrierServicesOfferedInternational.ToString();
            }


            _settingService.SaveSetting(_uspsSettings);

            return(Configure());
        }
Example #7
0
        public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            var model = new USPSShippingModel();

            model.Url      = _uspsSettings.Url;
            model.Username = _uspsSettings.Username;
            model.Password = _uspsSettings.Password;
            model.AdditionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge;

            // Load Domestic service names
            string carrierServicesOfferedDomestic = _uspsSettings.CarrierServicesOfferedDomestic;

            foreach (string service in USPSServices.DomesticServices)
            {
                model.AvailableCarrierServicesDomestic.Add(service);
            }

            if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic))
            {
                foreach (string service in USPSServices.DomesticServices)
                {
                    string serviceId = USPSServices.GetServiceIdDomestic(service);
                    if (!String.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        if (carrierServicesOfferedDomestic.Contains($"[{serviceId}]"))
                        {
                            model.CarrierServicesOfferedDomestic.Add(service);
                        }
                    }
                }
            }

            // Load Internation service names
            string carrierServicesOfferedInternational = _uspsSettings.CarrierServicesOfferedInternational;

            foreach (string service in USPSServices.InternationalServices)
            {
                model.AvailableCarrierServicesInternational.Add(service);
            }

            if (!String.IsNullOrEmpty(carrierServicesOfferedInternational))
            {
                foreach (string service in USPSServices.InternationalServices)
                {
                    string serviceId = USPSServices.GetServiceIdInternational(service);
                    if (!String.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        if (carrierServicesOfferedInternational.Contains($"[{serviceId}]"))
                        {
                            model.CarrierServicesOfferedInternational.Add(service);
                        }
                    }
                }
            }
            return(View("~/Plugins/Shipping.USPS/Views/Configure.cshtml", model));
        }
        public IActionResult Configure(USPSShippingModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _uspsSettings.Url      = model.Url;
            _uspsSettings.Username = model.Username;
            _uspsSettings.Password = model.Password;
            _uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge;

            // Save selected Domestic services
            var carrierServicesOfferedDomestic       = new StringBuilder();
            var carrierServicesDomesticSelectedCount = 0;

            if (model.CheckedCarrierServicesDomestic != null)
            {
                foreach (var cs in model.CheckedCarrierServicesDomestic)
                {
                    carrierServicesDomesticSelectedCount++;

                    var serviceId = USPSServices.GetServiceIdDomestic(cs);
                    //unselect any other services if NONE is selected
                    if (!string.IsNullOrEmpty(serviceId) && serviceId.Equals("NONE"))
                    {
                        carrierServicesOfferedDomestic.Clear();
                        carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId);
                        break;
                    }

                    if (!string.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId);
                    }
                }
            }
            // Add default options if no services were selected
            if (carrierServicesDomesticSelectedCount == 0)
            {
                _uspsSettings.CarrierServicesOfferedDomestic = "[1]:[3]:[4]:";
            }
            else
            {
                _uspsSettings.CarrierServicesOfferedDomestic = carrierServicesOfferedDomestic.ToString();
            }

            // Save selected International services
            var carrierServicesOfferedInternational       = new StringBuilder();
            var carrierServicesInternationalSelectedCount = 0;

            if (model.CheckedCarrierServicesInternational != null)
            {
                foreach (var cs in model.CheckedCarrierServicesInternational)
                {
                    carrierServicesInternationalSelectedCount++;
                    var serviceId = USPSServices.GetServiceIdInternational(cs);
                    // unselect other services if NONE is selected
                    if (!string.IsNullOrEmpty(serviceId) && serviceId.Equals("NONE"))
                    {
                        carrierServicesOfferedInternational.Clear();
                        carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId);
                        break;
                    }
                    if (!string.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId);
                    }
                }
            }
            // Add default options if no services were selected
            if (carrierServicesInternationalSelectedCount == 0)
            {
                _uspsSettings.CarrierServicesOfferedInternational = "[2]:[15]:[1]:";
            }
            else
            {
                _uspsSettings.CarrierServicesOfferedInternational = carrierServicesOfferedInternational.ToString();
            }

            _settingService.SaveSetting(_uspsSettings);

            _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return(Configure());
        }