Inheritance: Nop.Web.Framework.Mvc.BaseNopModel
Esempio n. 1
0
        public ActionResult RewardPoints(RewardPointsSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;

            if (ModelState.IsValid)
            {
                _rewardPointsSettings = model.ToEntity(_rewardPointsSettings);
                _settingService.SaveSetting(_rewardPointsSettings);

                //activity log
                _customerActivityService.InsertActivity("EditSettings", _localizationService.GetResource("ActivityLog.EditSettings"));

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"), false);
            }

            return View(model);
        }
        public ActionResult RewardPoints(RewardPointsSettingsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                //load settings for a chosen store scope
                var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
                var rewardPointsSettings = _settingService.LoadSetting<RewardPointsSettings>(storeScope);
                rewardPointsSettings = model.ToEntity(rewardPointsSettings);

                /* 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 */
                if (model.Enabled_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.Enabled, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.Enabled, storeScope);

                if (model.ExchangeRate_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.ExchangeRate, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.ExchangeRate, storeScope);

                if (model.MinimumRewardPointsToUse_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.MinimumRewardPointsToUse, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.MinimumRewardPointsToUse, storeScope);

                if (model.PointsForRegistration_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.PointsForRegistration, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.PointsForRegistration, storeScope);

                if (model.PointsForPurchases_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.PointsForPurchases_Amount, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.PointsForPurchases_Amount, storeScope);

                if (model.PointsForPurchases_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.PointsForPurchases_Points, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.PointsForPurchases_Points, storeScope);

                if (model.PointsForPurchases_Awarded_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.PointsForPurchases_Awarded, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.PointsForPurchases_Awarded, storeScope);

                if (model.PointsForPurchases_Canceled_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.PointsForPurchases_Canceled, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.PointsForPurchases_Canceled, storeScope);

                if (model.DisplayHowMuchWillBeEarned_OverrideForStore || storeScope == 0)
                    _settingService.SaveSetting(rewardPointsSettings, x => x.DisplayHowMuchWillBeEarned, storeScope, false);
                else if (storeScope > 0)
                    _settingService.DeleteSetting(rewardPointsSettings, x => x.DisplayHowMuchWillBeEarned, storeScope);

                //now clear settings cache
                _settingService.ClearCache();

                //activity log
                _customerActivityService.InsertActivity("EditSettings", _localizationService.GetResource("ActivityLog.EditSettings"));

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Updated"));
            }
            else
            {
                //If we got this far, something failed, redisplay form
                foreach (var modelState in ModelState.Values)
                    foreach (var error in modelState.Errors)
                        ErrorNotification(error.ErrorMessage);
            }
            return RedirectToAction("RewardPoints");
        }