Ejemplo n.º 1
0
        public IActionResult CookieInfoEditPopup(string name)
        {
            var ciList     = JsonConvert.DeserializeObject <List <CookieInfo> >(_privacySettings.CookieInfos);
            var cookieInfo = ciList
                             .Select(x => x)
                             .Where(x => x.Name.EqualsNoCase(name))
                             .FirstOrDefault();

            if (cookieInfo == null)
            {
                NotifyError(T("Admin.Configuration.Settings.CustomerUser.Privacy.Cookies.CookieInfoNotFound"));
                return(View(new CookieInfoModel()));
            }

            var model = new CookieInfoModel
            {
                CookieType       = cookieInfo.CookieType,
                Name             = cookieInfo.Name,
                Description      = cookieInfo.Description,
                SelectedStoreIds = cookieInfo.SelectedStoreIds
            };

            AddLocales(model.Locales, (locale, languageId) =>
            {
                locale.Name        = cookieInfo.GetLocalized(x => x.Name, languageId, false, false);
                locale.Description = cookieInfo.GetLocalized(x => x.Description, languageId, false, false);
            });

            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult CookieInfoCreatePopup()
        {
            var model = new CookieInfoModel();

            AddLocales(model.Locales);

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CookieInfoCreatePopup(CookieInfoModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Deserialize
            var ciList = JsonConvert.DeserializeObject <List <CookieInfo> >(_privacySettings.CookieInfos);

            if (ciList == null)
            {
                ciList = new List <CookieInfo>();
            }

            var cookieInfo = ciList
                             .Select(x => x)
                             .Where(x => x.Name.EqualsNoCase(model.Name))
                             .FirstOrDefault();

            if (cookieInfo != null)
            {
                // Remove item if it's already there.
                ciList.Remove(x => x.Name.EqualsNoCase(cookieInfo.Name));
            }

            cookieInfo = new CookieInfo
            {
                // TODO: Use MiniMapper
                CookieType       = model.CookieType,
                Name             = model.Name,
                Description      = model.Description,
                SelectedStoreIds = model.SelectedStoreIds
            };

            ciList.Add(cookieInfo);

            // Serialize
            _privacySettings.CookieInfos = JsonConvert.SerializeObject(ciList, Formatting.None);

            // Now apply & save again.
            await Services.Settings.ApplySettingAsync(_privacySettings, x => x.CookieInfos, 0);

            foreach (var localized in model.Locales)
            {
                await _localizedEntityService.ApplyLocalizedValueAsync(cookieInfo, x => x.Name, localized.Name, localized.LanguageId);

                await _localizedEntityService.ApplyLocalizedValueAsync(cookieInfo, x => x.Description, localized.Description, localized.LanguageId);
            }

            await _db.SaveChangesAsync();

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CookieInfoEditPopup(CookieInfoModel model)
        {
            var ciList     = JsonConvert.DeserializeObject <List <CookieInfo> >(_privacySettings.CookieInfos);
            var cookieInfo = ciList
                             .Select(x => x)
                             .Where(x => x.Name.EqualsNoCase(model.Name))
                             .FirstOrDefault();

            if (cookieInfo == null)
            {
                NotifyError(T("Admin.Configuration.Settings.CustomerUser.Privacy.Cookies.CookieInfoNotFound"));
                return(View(new CookieInfoModel()));
            }

            if (ModelState.IsValid)
            {
                cookieInfo.Name             = model.Name;
                cookieInfo.Description      = model.Description;
                cookieInfo.CookieType       = model.CookieType;
                cookieInfo.SelectedStoreIds = model.SelectedStoreIds;

                ciList.Remove(x => x.Name.EqualsNoCase(cookieInfo.Name));
                ciList.Add(cookieInfo);

                _privacySettings.CookieInfos = JsonConvert.SerializeObject(ciList, Formatting.None);

                await Services.Settings.ApplySettingAsync(_privacySettings, x => x.CookieInfos, 0);

                foreach (var localized in model.Locales)
                {
                    await _localizedEntityService.ApplyLocalizedValueAsync(cookieInfo, x => x.Name, localized.Name, localized.LanguageId);

                    await _localizedEntityService.ApplyLocalizedValueAsync(cookieInfo, x => x.Description, localized.Description, localized.LanguageId);
                }
            }

            return(View(model));
        }