protected override void PersistUpdatedItem(IDictionaryItem entity) { entity.UpdatingEntity(); foreach (var translation in entity.Translations) { translation.Value = translation.Value.ToValidXmlString(); } var dto = DictionaryItemFactory.BuildDto(entity); Database.Update(dto); foreach (var translation in entity.Translations) { var textDto = DictionaryTranslationFactory.BuildDto(translation, entity.Key); if (translation.HasIdentity) { Database.Update(textDto); } else { translation.Id = Convert.ToInt32(Database.Insert(textDto)); translation.Key = entity.Key; } } entity.ResetDirtyProperties(); //Clear the cache entries that exist by uniqueid/item key IsolatedCache.Clear(RepositoryCacheKeys.GetKey <IDictionaryItem, string>(entity.ItemKey)); IsolatedCache.Clear(RepositoryCacheKeys.GetKey <IDictionaryItem, Guid>(entity.Key)); }
protected override IDictionaryItem PerformGet(int id) { var sql = GetBaseQuery(false) .Where(GetBaseWhereClause(), new { Id = id }) .OrderBy <DictionaryDto>(x => x.UniqueId); var dto = Database.Fetch <DictionaryDto, LanguageTextDto, DictionaryDto>(new DictionaryLanguageTextRelator().Map, sql).FirstOrDefault(); if (dto == null) { return(null); } var factory = new DictionaryItemFactory(); var entity = factory.BuildEntity(dto); var list = new List <IDictionaryTranslation>(); foreach (var textDto in dto.LanguageTextDtos) { var language = _languageRepository.Get(textDto.LanguageId); var translationFactory = new DictionaryTranslationFactory(dto.UniqueId, language); list.Add(translationFactory.BuildEntity(textDto)); } entity.Translations = list; ((ICanBeDirty)entity).ResetDirtyProperties(); return(entity); }
protected override void PersistNewItem(IDictionaryItem entity) { var dictionaryItem = ((DictionaryItem)entity); dictionaryItem.AddingEntity(); foreach (var translation in dictionaryItem.Translations) { translation.Value = translation.Value.ToValidXmlString(); } var dto = DictionaryItemFactory.BuildDto(dictionaryItem); var id = Convert.ToInt32(Database.Insert(dto)); dictionaryItem.Id = id; foreach (var translation in dictionaryItem.Translations) { var textDto = DictionaryTranslationFactory.BuildDto(translation, dictionaryItem.Key); translation.Id = Convert.ToInt32(Database.Insert(textDto)); translation.Key = dictionaryItem.Key; } dictionaryItem.ResetDirtyProperties(); }
protected override void PersistUpdatedItem(IDictionaryItem entity) { ((Entity)entity).UpdatingEntity(); var factory = new DictionaryItemFactory(); var dto = factory.BuildDto(entity); Database.Update(dto); var translationFactory = new DictionaryTranslationFactory(entity.Key, null); foreach (var translation in entity.Translations) { var textDto = translationFactory.BuildDto(translation); if (translation.HasIdentity) { Database.Update(textDto); } else { translation.Id = Convert.ToInt32(Database.Insert(dto)); translation.Key = entity.Key; } } ((ICanBeDirty)entity).ResetDirtyProperties(); }
protected override void PersistNewItem(IDictionaryItem entity) { ((DictionaryItem)entity).AddingEntity(); foreach (var translation in entity.Translations) { translation.Value = translation.Value.ToValidXmlString(); } var factory = new DictionaryItemFactory(); var dto = factory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; var translationFactory = new DictionaryTranslationFactory(entity.Key, null); foreach (var translation in entity.Translations) { var textDto = translationFactory.BuildDto(translation); translation.Id = Convert.ToInt32(Database.Insert(textDto)); translation.Key = entity.Key; } entity.ResetDirtyProperties(); }
protected IDictionaryItem ConvertFromDto(DictionaryDto dto) { var entity = DictionaryItemFactory.BuildEntity(dto); entity.Translations = dto.LanguageTextDtos.EmptyNull() .Where(x => x.LanguageId > 0) .Select(x => DictionaryTranslationFactory.BuildEntity(x, dto.UniqueId)) .ToList(); return(entity); }
protected IDictionaryItem ConvertFromDto(DictionaryDto dto) { var factory = new DictionaryItemFactory(); var entity = factory.BuildEntity(dto); var list = new List <IDictionaryTranslation>(); foreach (var textDto in dto.LanguageTextDtos) { if (textDto.LanguageId <= 0) { continue; } var translationFactory = new DictionaryTranslationFactory(dto.UniqueId); list.Add(translationFactory.BuildEntity(textDto)); } entity.Translations = list; return(entity); }
protected IDictionaryItem ConvertFromDto(DictionaryDto dto, ILanguage[] allLanguages) { var factory = new DictionaryItemFactory(); var entity = factory.BuildEntity(dto); var list = new List <IDictionaryTranslation>(); foreach (var textDto in dto.LanguageTextDtos) { //Assuming this is cached! var language = allLanguages.FirstOrDefault(x => x.Id == textDto.LanguageId); if (language == null) { continue; } var translationFactory = new DictionaryTranslationFactory(dto.UniqueId, language); list.Add(translationFactory.BuildEntity(textDto)); } entity.Translations = list; return(entity); }
protected override void PersistUpdatedItem(IDictionaryItem entity) { ((Entity)entity).UpdatingEntity(); foreach (var translation in entity.Translations) { translation.Value = translation.Value.ToValidXmlString(); } var factory = new DictionaryItemFactory(); var dto = factory.BuildDto(entity); Database.Update(dto); var translationFactory = new DictionaryTranslationFactory(entity.Key, null); foreach (var translation in entity.Translations) { var textDto = translationFactory.BuildDto(translation); if (translation.HasIdentity) { Database.Update(textDto); } else { translation.Id = Convert.ToInt32(Database.Insert(textDto)); translation.Key = entity.Key; } } entity.ResetDirtyProperties(); //Clear the cache entries that exist by uniqueid/item key RuntimeCache.ClearCacheItem(GetCacheIdKey <IDictionaryItem>(entity.ItemKey)); RuntimeCache.ClearCacheItem(GetCacheIdKey <IDictionaryItem>(entity.Key)); }