Exemplo n.º 1
0
        public ActionResult Configure()
        {
            //load settings for a chosen store scope
            var storeScope          = _storeContext.ActiveStoreScopeConfiguration;
            var shipStationSettings = _settingService.LoadSetting <ShipStationSettings>(storeScope);

            var model = new ShipStationModel
            {
                ApiKey                        = shipStationSettings.ApiKey,
                ApiSecret                     = shipStationSettings.ApiSecret,
                PackingPackageVolume          = shipStationSettings.PackingPackageVolume,
                PackingType                   = Convert.ToInt32(shipStationSettings.PackingType),
                PackingTypeValues             = shipStationSettings.PackingType.ToSelectList(),
                PassDimensions                = shipStationSettings.PassDimensions,
                ActiveStoreScopeConfiguration = storeScope,
                UserName                      = shipStationSettings.UserName,
                Password                      = shipStationSettings.Password,
                WebhookURL                    = $"{_webHelper.GetStoreLocation()}Plugins/ShipStation/Webhook"
            };

            if (storeScope <= 0)
            {
                return(View("~/Plugins/Shipping.ShipStation/Views/Configure.cshtml", model));
            }

            model.ApiKey_OverrideForStore               = _settingService.SettingExists(shipStationSettings, x => x.ApiKey, storeScope);
            model.ApiSecret_OverrideForStore            = _settingService.SettingExists(shipStationSettings, x => x.ApiSecret, storeScope);
            model.PackingPackageVolume_OverrideForStore = _settingService.SettingExists(shipStationSettings, x => x.PackingPackageVolume, storeScope);
            model.PackingType_OverrideForStore          = _settingService.SettingExists(shipStationSettings, x => x.PackingType, storeScope);
            model.PassDimensions_OverrideForStore       = _settingService.SettingExists(shipStationSettings, x => x.PassDimensions, storeScope);
            model.Password_OverrideForStore             = _settingService.SettingExists(shipStationSettings, x => x.Password, storeScope);
            model.UserName_OverrideForStore             = _settingService.SettingExists(shipStationSettings, x => x.UserName, storeScope);

            return(View("~/Plugins/Shipping.ShipStation/Views/Configure.cshtml", model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Configure(ShipStationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(await Configure());
            }

            //load settings for a chosen store scope
            var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync();

            var shipStationSettings = await _settingService.LoadSettingAsync <ShipStationSettings>(storeScope);

            //save settings
            shipStationSettings.ApiKey               = model.ApiKey;
            shipStationSettings.ApiSecret            = model.ApiSecret;
            shipStationSettings.PackingPackageVolume = model.PackingPackageVolume;
            shipStationSettings.PackingType          = (PackingType)model.PackingType;
            shipStationSettings.PassDimensions       = model.PassDimensions;
            shipStationSettings.Password             = model.Password;
            shipStationSettings.UserName             = model.UserName;

            /* We do not clear cache after each setting update.
             * This behavior can increase performance because cached settings will not be cleared
             * and loaded from database after each update */
            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.ApiKey, model.ApiKey_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.ApiSecret, model.ApiSecret_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.PackingPackageVolume, model.PackingPackageVolume_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.PackingType, model.PackingType_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.PassDimensions, model.PassDimensions_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.Password, model.Password_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.UserName, model.UserName_OverrideForStore, storeScope, false);

            //now clear settings cache
            await _settingService.ClearCacheAsync();

            _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved"));

            return(await Configure());
        }