Created
July 13, 2019 09:39
-
-
Save DmitrySikorsky/106a851b0098884df10877ebcc9aac35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private LocalizationSet GetOrCreateLocalizationSetForProperty(object entity, PropertyInfo propertyInfo) | |
{ | |
ILocalizationSetRepository localizationSetRepository = this.HttpContext.RequestServices.GetService<ILocalizationSetRepository>(); | |
Storage storage = this.HttpContext.RequestServices.GetService<Storage>(); | |
PropertyInfo localizationSetIdPropertyInfo = entity.GetType().GetProperty(propertyInfo.Name + "Id"); | |
int? localizationSetId = (int?)localizationSetIdPropertyInfo.GetValue(entity); | |
LocalizationSet localizationSet = null; | |
if (localizationSetId == null || localizationSetId == 0) | |
{ | |
localizationSet = new LocalizationSet(); | |
localizationSetRepository.Create(localizationSet); | |
storage.SaveChanges(); | |
localizationSetIdPropertyInfo.SetValue(entity, localizationSet.Id); | |
} | |
else localizationSet = localizationSetRepository.GetById((int)localizationSetId); | |
return localizationSet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment