public virtual void Delete(TblLocalizedProperty localizedProperty) { if (localizedProperty == null) { throw new ArgumentNullException(nameof(localizedProperty)); } _dbContext.LocalizedProperty.Where(p => p.Id == localizedProperty.Id).Delete(); ClearCache(); }
public virtual void Add(TblLocalizedProperty localizedProperty) { if (localizedProperty == null) { throw new ArgumentNullException(nameof(localizedProperty)); } _dbContext.LocalizedProperty.Add(localizedProperty); _dbContext.SaveChanges(); ClearCache(); }
public virtual async Task DeleteAsync(TblLocalizedProperty localizedProperty) { if (localizedProperty == null) { throw new ArgumentNullException(nameof(localizedProperty)); } await _dbContext.LocalizedProperty.Where(p => p.Id == localizedProperty.Id).DeleteAsync(); _eventPublisher.EntityDeleted(localizedProperty); ClearCache(); }
public virtual async Task SaveLocalizedStringAsync <T, TPropType>(T entity, string localeKey, string localeKeyGroup, TPropType localeValue, int languageId) where T : BaseEntity { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (languageId == 0) { throw new ArgumentOutOfRangeException(nameof(languageId), @"Language ID should not be 0"); } var props = GetLocalizedProperties(entity.Id, localeKeyGroup); var prop = props.FirstOrDefault(lp => lp.LanguageId == languageId && lp.LocaleKey.Equals(localeKey, StringComparison.InvariantCultureIgnoreCase)); //should be culture invariant var localeValueStr = localeValue.To <string>(); if (prop != null) { if (string.IsNullOrWhiteSpace(localeValueStr)) { //delete await DeleteAsync(prop); } else { //update prop.LocaleValue = localeValueStr; await UpdateAsync(prop); } } else { if (!string.IsNullOrWhiteSpace(localeValueStr)) { //insert prop = new TblLocalizedProperty() { EntityId = entity.Id, LanguageId = languageId, LocaleKey = localeKey, LocaleKeyGroup = localeKeyGroup, LocaleValue = localeValueStr }; await AddAsync(prop); } } }
public virtual async Task AddAsync(TblLocalizedProperty localizedProperty) { if (localizedProperty == null) { throw new ArgumentNullException(nameof(localizedProperty)); } _dbContext.LocalizedProperty.Add(localizedProperty); await _dbContext.SaveChangesAsync(); _eventPublisher.EntityInserted(localizedProperty); ClearCache(); }
public virtual void Update(TblLocalizedProperty localizedProperty) { if (localizedProperty == null) { throw new ArgumentNullException(nameof(localizedProperty)); } _dbContext.LocalizedProperty.Where(p => p.Id == localizedProperty.Id).Update(p => new TblLocalizedProperty() { EntityId = localizedProperty.EntityId, LanguageId = localizedProperty.LanguageId, LocaleKey = localizedProperty.LocaleKey, LocaleKeyGroup = localizedProperty.LocaleKeyGroup, LocaleValue = localizedProperty.LocaleValue }); ClearCache(); }
public virtual void SaveLocalizedSetting <T>(T setting, string localeKeyGroup, string localeKey, LocalizedString localizedString) where T : ISettings { foreach (var item in localizedString.Where(p => p.Key != 0)) { var languageId = item.Key; var props = GetLocalizedProperties(0, localeKeyGroup); var prop = props.FirstOrDefault(lp => lp.LanguageId == languageId && lp.LocaleKey.Equals(localeKey, StringComparison.InvariantCultureIgnoreCase)); //should be culture invariant var localeValueStr = item.Value; if (prop != null) { if (string.IsNullOrWhiteSpace(localeValueStr)) { //delete Delete(prop); } else { //update prop.LocaleValue = localeValueStr; Update(prop); } } else { if (!string.IsNullOrWhiteSpace(localeValueStr)) { //insert prop = new TblLocalizedProperty() { EntityId = 0, LanguageId = languageId, LocaleKey = localeKey, LocaleKeyGroup = localeKeyGroup, LocaleValue = localeValueStr }; Add(prop); } } } }
public virtual async Task UpdateAsync(TblLocalizedProperty localizedProperty) { if (localizedProperty == null) { throw new ArgumentNullException(nameof(localizedProperty)); } var oldRecord = FindById(localizedProperty.Id); await _dbContext.LocalizedProperty.Where(p => p.Id == localizedProperty.Id).UpdateAsync(p => new TblLocalizedProperty() { EntityId = localizedProperty.EntityId, LanguageId = localizedProperty.LanguageId, LocaleKey = localizedProperty.LocaleKey, LocaleKeyGroup = localizedProperty.LocaleKeyGroup, LocaleValue = localizedProperty.LocaleValue }); _eventPublisher.EntityUpdated(localizedProperty, oldRecord); ClearCache(); }
public virtual string GetLocalizedString(int languageId, int entityId, string localeKeyGroup, string localeKey) { TblLocalizedProperty tblLocalizedProperty = null; if (_useCache) { tblLocalizedProperty = GetAllResourcesFromCache().FirstOrDefault(p => p.LanguageId == languageId && p.EntityId == entityId && p.LocaleKeyGroup == localeKeyGroup && p.LocaleKey == localeKey); } else { tblLocalizedProperty = _dbContext.LocalizedProperty .DeferredFirstOrDefault(p => p.LanguageId == languageId && p.EntityId == entityId && p.LocaleKeyGroup == localeKeyGroup && p.LocaleKey == localeKey) .FromCache(CacheTags.LocalizedProperty); } if (tblLocalizedProperty != null) { return(tblLocalizedProperty.LocaleValue); } return(string.Empty); }