Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created July 13, 2019 09:39
Show Gist options
  • Save DmitrySikorsky/106a851b0098884df10877ebcc9aac35 to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/106a851b0098884df10877ebcc9aac35 to your computer and use it in GitHub Desktop.
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