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)); }
private async Task UpdateLocalesAsync(Topic topic, TopicModel model) { foreach (var localized in model.Locales) { await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.ShortTitle, localized.ShortTitle, localized.LanguageId); await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.Title, localized.Title, localized.LanguageId); await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.Intro, localized.Intro, localized.LanguageId); await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.Body, localized.Body, localized.LanguageId); await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); await _localizedEntityService.ApplyLocalizedValueAsync(topic, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); await _db.SaveChangesAsync(); var slugResult = await topic.ValidateSlugAsync(localized.SeName, true); model.SeName = slugResult.Slug; await _urlService.ApplySlugAsync(slugResult, true); } }
private async Task InternalCopyFileData(MediaFile file, MediaFile copy) { await _storageProvider.SaveAsync(copy, MediaStorageItem.FromStream(await _storageProvider.OpenReadAsync(file))); await _imageCache.DeleteAsync(copy); // Tags. await _db.LoadCollectionAsync(file, (MediaFile x) => x.Tags); var existingTagsIds = copy.Tags.Select(x => x.Id).ToList(); foreach (var tag in file.Tags) { if (!existingTagsIds.Contains(tag.Id)) { copy.Tags.Add(tag); existingTagsIds.Add(tag.Id); } } // Localized values. var languages = _languageService.GetAllLanguages(true); foreach (var language in languages) { var title = file.GetLocalized(x => x.Title, language.Id, false, false).Value; if (title.HasValue()) { await _localizedEntityService.ApplyLocalizedValueAsync(copy, x => x.Title, title, language.Id); } var alt = file.GetLocalized(x => x.Alt, language.Id, false, false).Value; if (alt.HasValue()) { await _localizedEntityService.ApplyLocalizedValueAsync(copy, x => x.Alt, alt, language.Id); } } await _db.SaveChangesAsync(); _db.DetachEntities <MediaTag>(); }
private async Task ProcessLocalizations <T>(T source, T target, List <Expression <Func <T, string> > > keySelectors, IEnumerable <Language> languages) where T : BaseEntity, ILocalizedEntity { foreach (var lang in languages) { foreach (var keySelector in keySelectors) { string value = source.GetLocalized(keySelector, lang, false, false); if (value.HasValue()) { await _localizedEntityService.ApplyLocalizedValueAsync(target, keySelector, value, lang.Id); } } } }