protected override void InitializePropertiesForViewing() { using (var _appConfigRepository = _appConfigRepositoryFactory.GetRepositoryInstance()) { SeoKeywords = _appConfigRepository.SeoUrlKeywords.Where( keyword => keyword.KeywordValue.Equals(InnerItem.Code) && keyword.KeywordType.Equals((int)SeoUrlKeywordTypes.Item)) .ToList(); } InnerItemCatalogLanguages.ForEach(locale => { if (!SeoKeywords.Any(keyword => keyword.Language.Equals(locale))) { var newSeoKeyword = new SeoUrlKeyword { Language = locale, IsActive = true, KeywordType = (int)SeoUrlKeywordTypes.Item, KeywordValue = InnerItem.Code, Created = DateTime.UtcNow }; SeoKeywords.Add(newSeoKeyword); } }); // filter values by locale SeoLocalesFilterCommand.Execute(InnerItem.Catalog.DefaultLanguage); }
protected override void InitializePropertiesForViewing() { using (var _appConfigRepository = _appConfigRepositoryFactory.GetRepositoryInstance()) { SeoKeywords = _appConfigRepository.SeoUrlKeywords.Where( keyword => keyword.KeywordValue.Equals(InnerItem.Code) && keyword.KeywordType.Equals((int)SeoUrlKeywordTypes.Category)) .ToList(); } var innerItemCatalog = _parentCatalog as catalogModel.Catalog; if (innerItemCatalog == null) { using (var storeRepository = _storeRepositoryFactory.GetRepositoryInstance()) { var languages = storeRepository.Stores.Where(store => store.Catalog == _parentCatalog.CatalogId) .Expand(store => store.Languages).ToList(); var customComparer = new PropertyComparer <StoreLanguage>("LanguageCode"); var lang = languages.SelectMany(x => x.Languages).Distinct(customComparer); InnerItemCatalogLanguages = new List <string>(); if (lang.Any()) { foreach (var l in lang) { InnerItemCatalogLanguages.Add(l.LanguageCode); } } } } InnerItemCatalogLanguages.ForEach(locale => { if (!SeoKeywords.Any(keyword => keyword.Language.Equals(locale))) { SeoKeywords.Add(CreateSeoUrlKeyword(locale)); } }); // filter values by locale SeoLocalesFilterCommand.Execute(_parentCatalog.DefaultLanguage); }
public void UpdateSeoKeywords() { //if item code changed - need to update SEO KeywordValue property, if any if (!OriginalItem.Code.Equals(InnerItem.Code)) { if (SeoKeywords.Any(kw => !string.IsNullOrEmpty(kw.Keyword))) { if (CurrentSeoKeyword != null) { CurrentSeoKeyword.PropertyChanged -= CurrentSeoKeyword_PropertyChanged; } _seoModified = true; SeoKeywords.ForEach(keyword => { if (!string.IsNullOrEmpty(keyword.Keyword)) { keyword.KeywordValue = InnerItem.Code; } }); if (CurrentSeoKeyword != null) { CurrentSeoKeyword.PropertyChanged -= CurrentSeoKeyword_PropertyChanged; } } } //if any SEO keyword modified update or add it if (_seoModified) { using (var appConfigRepository = _appConfigRepositoryFactory.GetRepositoryInstance()) { SeoKeywords.ForEach(keyword => { if (!string.IsNullOrEmpty(keyword.Keyword)) { var originalKeyword = appConfigRepository.SeoUrlKeywords.Where( seoKeyword => true && seoKeyword.SeoUrlKeywordId.Equals(keyword.SeoUrlKeywordId)) .FirstOrDefault(); if (originalKeyword != null) { originalKeyword.InjectFrom <CloneInjection>(keyword); appConfigRepository.Update(originalKeyword); } else { var addKeyword = _appConfigEntityFactory.CreateEntity <SeoUrlKeyword>(); addKeyword.InjectFrom(keyword); appConfigRepository.Add(addKeyword); } } }); appConfigRepository.UnitOfWork.Commit(); } OnPropertyChanged("NavigateUri"); _seoModified = false; } }