public void AddNewLocalizedItem(string key, string culture, string resourceKey) { if (_requestLocalizationOptions.Value.SupportedCultures.Contains(new System.Globalization.CultureInfo(culture))) { string computedKey = $"{key}.{culture}"; LocalizationRecord localizationRecord = new LocalizationRecord() { LocalizationCulture = culture, Key = key, Text = computedKey, ResourceKey = resourceKey }; _context.LocalizationRecords.Add(localizationRecord); _context.SaveChanges(); } }
private List<LocalizationRecord> readStream(Stream stream) { bool skipFirstLine = true; string csvDelimiter = ";"; List<LocalizationRecord> list = new List<LocalizationRecord>(); var reader = new StreamReader(stream); while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(csvDelimiter.ToCharArray()); if (skipFirstLine) { skipFirstLine = false; } else { var itemTypeInGeneric = list.GetType().GetTypeInfo().GenericTypeArguments[0]; var item = new LocalizationRecord(); var properties = item.GetType().GetProperties(); for (int i = 0; i < values.Length; i++) { properties[i].SetValue(item, Convert.ChangeType(values[i], properties[i].PropertyType), null); } list.Add(item); } } return list; }