using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Media;
using Nop.Services.Messages;
using Nop.Services.Security;
using Nop.Web.Areas.Admin.Models.HomePageBannerB2C;
using Nop.Web.Framework;
using Nop.Web.Framework.Controllers;

namespace Nop.Web.Areas.Admin.Controllers
{
    public class HomePageBannerB2CController : BaseAdminController
    {
        private readonly ILocalizationService _localizationService;
        private readonly INotificationService _notificationService;
        private readonly IPermissionService _permissionService;
        private readonly IPictureService _pictureService;
        private readonly ISettingService _settingService;
        private readonly IStoreContext _storeContext;

        public HomePageBannerB2CController(ILocalizationService localizationService,
            INotificationService notificationService,
            IPermissionService permissionService,
            IPictureService pictureService,
            ISettingService settingService,
            IStoreContext storeContext)
        {
            _localizationService = localizationService;
            _notificationService = notificationService;
            _permissionService = permissionService;
            _pictureService = pictureService;
            _settingService = settingService;
            _storeContext = storeContext;
        }

        public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets))
                return AccessDeniedView();

            //load settings for a chosen store scope
            var storeScope = _storeContext.ActiveStoreScopeConfiguration;
            var homePageBannerSettings = _settingService.LoadSetting<HomePageBannerB2CSettings>(storeScope);
            var model = new HomePageBannerB2CModel
            {
                PictureDesktop1Id = homePageBannerSettings.PictureDesktop1Id,
                PictureMobile1Id = homePageBannerSettings.PictureMobile1Id,
                PictureTablet1Id = homePageBannerSettings.PictureTablet1Id,
                Text1 = homePageBannerSettings.Text1,
                Link1 = homePageBannerSettings.Link1,
                AltText1 = homePageBannerSettings.AltText1,

                PictureDesktop2Id = homePageBannerSettings.PictureDesktop2Id,
                PictureMobile2Id = homePageBannerSettings.PictureMobile2Id,
                PictureTablet2Id = homePageBannerSettings.PictureTablet2Id,
                Text2 = homePageBannerSettings.Text2,
                Link2 = homePageBannerSettings.Link2,
                AltText2 = homePageBannerSettings.AltText2,

                PictureDesktop3Id = homePageBannerSettings.PictureDesktop3Id,
                PictureMobile3Id = homePageBannerSettings.PictureMobile3Id,
                PictureTablet3Id = homePageBannerSettings.PictureTablet3Id,
                Text3 = homePageBannerSettings.Text3,
                Link3 = homePageBannerSettings.Link3,
                AltText3 = homePageBannerSettings.AltText3,

                PictureDesktop4Id = homePageBannerSettings.PictureDesktop4Id,
                PictureMobile4Id = homePageBannerSettings.PictureMobile4Id,
                PictureTablet4Id = homePageBannerSettings.PictureTablet4Id,
                Text4 = homePageBannerSettings.Text4,
                Link4 = homePageBannerSettings.Link4,
                AltText4 = homePageBannerSettings.AltText4,

                PictureDesktop5Id = homePageBannerSettings.PictureDesktop5Id,
                PictureMobile5Id = homePageBannerSettings.PictureMobile5Id,
                PictureTablet5Id = homePageBannerSettings.PictureTablet5Id,
                Text5 = homePageBannerSettings.Text5,
                Link5 = homePageBannerSettings.Link5,
                AltText5 = homePageBannerSettings.AltText5,

                PictureDesktop6Id = homePageBannerSettings.PictureDesktop6Id,
                PictureMobile6Id = homePageBannerSettings.PictureMobile6Id,
                PictureTablet6Id = homePageBannerSettings.PictureTablet6Id,
                Text6 = homePageBannerSettings.Text6,
                Link6 = homePageBannerSettings.Link6,
                AltText6 = homePageBannerSettings.AltText6,

                PictureDesktop7Id = homePageBannerSettings.PictureDesktop7Id,
                PictureMobile7Id = homePageBannerSettings.PictureMobile7Id,
                PictureTablet7Id = homePageBannerSettings.PictureTablet7Id,
                Text7 = homePageBannerSettings.Text7,
                Link7 = homePageBannerSettings.Link7,
                AltText7 = homePageBannerSettings.AltText7,

                PictureDesktop8Id = homePageBannerSettings.PictureDesktop8Id,
                PictureMobile8Id = homePageBannerSettings.PictureMobile8Id,
                PictureTablet8Id = homePageBannerSettings.PictureTablet8Id,
                Text8 = homePageBannerSettings.Text8,
                Link8 = homePageBannerSettings.Link8,
                AltText8 = homePageBannerSettings.AltText8,

                PictureDesktop9Id = homePageBannerSettings.PictureDesktop9Id,
                PictureMobile9Id = homePageBannerSettings.PictureMobile9Id,
                PictureTablet9Id = homePageBannerSettings.PictureTablet9Id,
                Text9 = homePageBannerSettings.Text9,
                Link9 = homePageBannerSettings.Link9,
                AltText9 = homePageBannerSettings.AltText9,

                PictureDesktop10Id = homePageBannerSettings.PictureDesktop10Id,
                PictureMobile10Id = homePageBannerSettings.PictureMobile10Id,
                PictureTablet10Id = homePageBannerSettings.PictureTablet10Id,
                Text10 = homePageBannerSettings.Text10,
                Link10 = homePageBannerSettings.Link10,
                AltText10 = homePageBannerSettings.AltText10,

                ActiveStoreScopeConfiguration = storeScope
            };

            if (storeScope > 0)
            {
                model.PictureDesktop1Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop1Id, storeScope);
                model.PictureMobile1Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile1Id, storeScope);
                model.PictureTablet1Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet1Id, storeScope);
                model.Text1_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text1, storeScope);
                model.Link1_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link1, storeScope);
                model.AltText1_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText1, storeScope);

                model.PictureDesktop2Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop2Id, storeScope);
                model.PictureMobile2Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile2Id, storeScope);
                model.PictureTablet2Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet2Id, storeScope);
                model.Text2_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text2, storeScope);
                model.Link2_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link2, storeScope);
                model.AltText2_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText2, storeScope);

                model.PictureDesktop3Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop3Id, storeScope);
                model.PictureMobile3Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile3Id, storeScope);
                model.PictureTablet3Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet3Id, storeScope);
                model.Text3_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text3, storeScope);
                model.Link3_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link3, storeScope);
                model.AltText3_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText3, storeScope);

                model.PictureDesktop4Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop4Id, storeScope);
                model.PictureMobile4Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile4Id, storeScope);
                model.PictureTablet4Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet4Id, storeScope);
                model.Text4_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text4, storeScope);
                model.Link4_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link4, storeScope);
                model.AltText4_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText4, storeScope);

                model.PictureDesktop5Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop5Id, storeScope);
                model.PictureMobile5Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile5Id, storeScope);
                model.PictureTablet5Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet5Id, storeScope);
                model.Text5_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text5, storeScope);
                model.Link5_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link5, storeScope);
                model.AltText5_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText5, storeScope);

                model.PictureDesktop6Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop6Id, storeScope);
                model.PictureMobile6Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile6Id, storeScope);
                model.PictureTablet6Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet6Id, storeScope);
                model.Text6_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text6, storeScope);
                model.Link6_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link6, storeScope);
                model.AltText6_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText6, storeScope);

                model.PictureDesktop7Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop7Id, storeScope);
                model.PictureMobile7Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile7Id, storeScope);
                model.PictureTablet7Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet7Id, storeScope);
                model.Text7_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text7, storeScope);
                model.Link7_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link7, storeScope);
                model.AltText7_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText7, storeScope);

                model.PictureDesktop8Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop8Id, storeScope);
                model.PictureMobile8Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile8Id, storeScope);
                model.PictureTablet8Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet8Id, storeScope);
                model.Text8_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text8, storeScope);
                model.Link8_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link8, storeScope);
                model.AltText8_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText8, storeScope);

                model.PictureDesktop9Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop9Id, storeScope);
                model.PictureMobile9Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile9Id, storeScope);
                model.PictureTablet9Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet9Id, storeScope);
                model.Text9_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text9, storeScope);
                model.Link9_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link9, storeScope);
                model.AltText9_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText9, storeScope);

                model.PictureDesktop10Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureDesktop10Id, storeScope);
                model.PictureMobile10Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureMobile10Id, storeScope);
                model.PictureTablet10Id_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.PictureTablet10Id, storeScope);
                model.Text10_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Text10, storeScope);
                model.Link10_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.Link10, storeScope);
                model.AltText10_OverrideForStore = _settingService.SettingExists(homePageBannerSettings, x => x.AltText10, storeScope);
            }

            return View(model);
        }

        [HttpPost]
        public IActionResult Configure(HomePageBannerB2CModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets))
                return AccessDeniedView();

            //load settings for a chosen store scope
            var storeScope = _storeContext.ActiveStoreScopeConfiguration;
            var nivoSliderSettings = _settingService.LoadSetting<HomePageBannerB2CSettings>(storeScope);

            //get previous picture identifiers
            var previousPictureIds = new[]
            {
                nivoSliderSettings.PictureDesktop1Id,
                nivoSliderSettings.PictureMobile1Id,
                nivoSliderSettings.PictureTablet1Id,

                nivoSliderSettings.PictureDesktop2Id,
                nivoSliderSettings.PictureMobile2Id,
                nivoSliderSettings.PictureTablet2Id,

                nivoSliderSettings.PictureDesktop3Id,
                nivoSliderSettings.PictureMobile3Id,
                nivoSliderSettings.PictureTablet3Id,

                nivoSliderSettings.PictureDesktop4Id,
                nivoSliderSettings.PictureMobile4Id,
                nivoSliderSettings.PictureTablet4Id,

                nivoSliderSettings.PictureDesktop5Id,
                nivoSliderSettings.PictureMobile5Id,
                nivoSliderSettings.PictureTablet5Id,

                nivoSliderSettings.PictureDesktop6Id,
                nivoSliderSettings.PictureMobile6Id,
                nivoSliderSettings.PictureTablet6Id,

                nivoSliderSettings.PictureDesktop7Id,
                nivoSliderSettings.PictureMobile7Id,
                nivoSliderSettings.PictureTablet7Id,

                nivoSliderSettings.PictureDesktop8Id,
                nivoSliderSettings.PictureMobile8Id,
                nivoSliderSettings.PictureTablet8Id,

                nivoSliderSettings.PictureDesktop9Id,
                nivoSliderSettings.PictureMobile9Id,
                nivoSliderSettings.PictureTablet9Id,

                nivoSliderSettings.PictureDesktop10Id,
                nivoSliderSettings.PictureMobile10Id,
                nivoSliderSettings.PictureTablet10Id,
            };

            nivoSliderSettings.PictureDesktop1Id = model.PictureDesktop1Id;
            nivoSliderSettings.PictureMobile1Id = model.PictureMobile1Id;
            nivoSliderSettings.PictureTablet1Id = model.PictureTablet1Id;
            nivoSliderSettings.Text1 = model.Text1;
            nivoSliderSettings.Link1 = model.Link1;
            nivoSliderSettings.AltText1 = model.AltText1;

            nivoSliderSettings.PictureDesktop2Id = model.PictureDesktop2Id;
            nivoSliderSettings.PictureMobile2Id = model.PictureMobile2Id;
            nivoSliderSettings.PictureTablet2Id = model.PictureTablet2Id;
            nivoSliderSettings.Text2 = model.Text2;
            nivoSliderSettings.Link2 = model.Link2;
            nivoSliderSettings.AltText2 = model.AltText2;

            nivoSliderSettings.PictureDesktop3Id = model.PictureDesktop3Id;
            nivoSliderSettings.PictureMobile3Id = model.PictureMobile3Id;
            nivoSliderSettings.PictureTablet3Id = model.PictureTablet3Id;
            nivoSliderSettings.Text3 = model.Text3;
            nivoSliderSettings.Link3 = model.Link3;
            nivoSliderSettings.AltText3 = model.AltText3;

            nivoSliderSettings.PictureDesktop4Id = model.PictureDesktop4Id;
            nivoSliderSettings.PictureMobile4Id = model.PictureMobile4Id;
            nivoSliderSettings.PictureTablet4Id = model.PictureTablet4Id;
            nivoSliderSettings.Text4 = model.Text4;
            nivoSliderSettings.Link4 = model.Link4;
            nivoSliderSettings.AltText4 = model.AltText4;

            nivoSliderSettings.PictureDesktop5Id = model.PictureDesktop5Id;
            nivoSliderSettings.PictureMobile5Id = model.PictureMobile5Id;
            nivoSliderSettings.PictureTablet5Id = model.PictureTablet5Id;
            nivoSliderSettings.Text5 = model.Text5;
            nivoSliderSettings.Link5 = model.Link5;
            nivoSliderSettings.AltText5 = model.AltText5;

            nivoSliderSettings.PictureDesktop6Id = model.PictureDesktop6Id;
            nivoSliderSettings.PictureMobile6Id = model.PictureMobile6Id;
            nivoSliderSettings.PictureTablet6Id = model.PictureTablet6Id;
            nivoSliderSettings.Text6 = model.Text6;
            nivoSliderSettings.Link6 = model.Link6;
            nivoSliderSettings.AltText6 = model.AltText6;

            nivoSliderSettings.PictureDesktop7Id = model.PictureDesktop7Id;
            nivoSliderSettings.PictureMobile7Id = model.PictureMobile7Id;
            nivoSliderSettings.PictureTablet7Id = model.PictureTablet7Id;
            nivoSliderSettings.Text7 = model.Text7;
            nivoSliderSettings.Link7 = model.Link7;
            nivoSliderSettings.AltText7 = model.AltText7;

            nivoSliderSettings.PictureDesktop8Id = model.PictureDesktop8Id;
            nivoSliderSettings.PictureMobile8Id = model.PictureMobile8Id;
            nivoSliderSettings.PictureTablet8Id = model.PictureTablet8Id;
            nivoSliderSettings.Text8 = model.Text8;
            nivoSliderSettings.Link8 = model.Link8;
            nivoSliderSettings.AltText8 = model.AltText8;

            nivoSliderSettings.PictureDesktop9Id = model.PictureDesktop9Id;
            nivoSliderSettings.PictureMobile9Id = model.PictureMobile9Id;
            nivoSliderSettings.PictureTablet9Id = model.PictureTablet9Id;
            nivoSliderSettings.Text9 = model.Text9;
            nivoSliderSettings.Link9 = model.Link9;
            nivoSliderSettings.AltText9 = model.AltText9;

            nivoSliderSettings.PictureDesktop10Id = model.PictureDesktop10Id;
            nivoSliderSettings.PictureMobile10Id = model.PictureMobile10Id;
            nivoSliderSettings.PictureTablet10Id = model.PictureTablet10Id;
            nivoSliderSettings.Text10 = model.Text10;
            nivoSliderSettings.Link10 = model.Link10;
            nivoSliderSettings.AltText10 = model.AltText10;

            /* 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 */
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop1Id, model.PictureDesktop1Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile1Id, model.PictureMobile1Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet1Id, model.PictureTablet1Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text1, model.Text1_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link1, model.Link1_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText1, model.AltText1_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop2Id, model.PictureDesktop2Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile2Id, model.PictureMobile2Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet2Id, model.PictureTablet2Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text2, model.Text2_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link2, model.Link2_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText2, model.AltText2_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop3Id, model.PictureDesktop3Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile3Id, model.PictureMobile3Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet3Id, model.PictureTablet3Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text3, model.Text3_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link3, model.Link3_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText3, model.AltText3_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop4Id, model.PictureDesktop4Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile4Id, model.PictureMobile4Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet4Id, model.PictureTablet4Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text4, model.Text4_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link4, model.Link4_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText4, model.AltText4_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop5Id, model.PictureDesktop5Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile5Id, model.PictureMobile5Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet5Id, model.PictureTablet5Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text5, model.Text5_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link5, model.Link5_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText5, model.AltText5_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop6Id, model.PictureDesktop6Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile6Id, model.PictureMobile6Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet6Id, model.PictureTablet6Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text6, model.Text6_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link6, model.Link6_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText6, model.AltText6_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop7Id, model.PictureDesktop7Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile7Id, model.PictureMobile7Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet7Id, model.PictureTablet7Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text7, model.Text7_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link7, model.Link7_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText7, model.AltText7_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop8Id, model.PictureDesktop8Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile8Id, model.PictureMobile8Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet8Id, model.PictureTablet8Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text8, model.Text8_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link8, model.Link8_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText8, model.AltText8_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop9Id, model.PictureDesktop9Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile9Id, model.PictureMobile9Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet9Id, model.PictureTablet9Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text9, model.Text9_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link9, model.Link9_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText9, model.AltText9_OverrideForStore, storeScope, false);

            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureDesktop10Id, model.PictureDesktop10Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureMobile10Id, model.PictureMobile10Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.PictureTablet10Id, model.PictureTablet10Id_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Text10, model.Text10_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.Link10, model.Link10_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(nivoSliderSettings, x => x.AltText10, model.AltText10_OverrideForStore, storeScope, false);

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

            //get current picture identifiers
            var currentPictureIds = new[]
            {
                nivoSliderSettings.PictureDesktop1Id,
                nivoSliderSettings.PictureMobile1Id,
                nivoSliderSettings.PictureTablet1Id,

                nivoSliderSettings.PictureDesktop2Id,
                nivoSliderSettings.PictureMobile2Id,
                nivoSliderSettings.PictureTablet2Id,

                nivoSliderSettings.PictureDesktop3Id,
                nivoSliderSettings.PictureMobile3Id,
                nivoSliderSettings.PictureTablet3Id,

                nivoSliderSettings.PictureDesktop4Id,
                nivoSliderSettings.PictureMobile4Id,
                nivoSliderSettings.PictureTablet4Id,

                nivoSliderSettings.PictureDesktop5Id,
                nivoSliderSettings.PictureMobile5Id,
                nivoSliderSettings.PictureTablet5Id,

                nivoSliderSettings.PictureDesktop6Id,
                nivoSliderSettings.PictureMobile6Id,
                nivoSliderSettings.PictureTablet6Id,

                nivoSliderSettings.PictureDesktop7Id,
                nivoSliderSettings.PictureMobile7Id,
                nivoSliderSettings.PictureTablet7Id,

                nivoSliderSettings.PictureDesktop8Id,
                nivoSliderSettings.PictureMobile8Id,
                nivoSliderSettings.PictureTablet8Id,

                nivoSliderSettings.PictureDesktop9Id,
                nivoSliderSettings.PictureMobile9Id,
                nivoSliderSettings.PictureTablet9Id,

                nivoSliderSettings.PictureDesktop10Id,
                nivoSliderSettings.PictureMobile10Id,
                nivoSliderSettings.PictureTablet10Id,
            };

            //delete an old picture (if deleted or updated)
            foreach (var pictureId in previousPictureIds.Except(currentPictureIds))
            {
                var previousPicture = _pictureService.GetPictureById(pictureId);
                if (previousPicture != null)
                    _pictureService.DeletePicture(previousPicture);
            }

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