private string Insert(IEnumerable <string> enumerable) { using (var context = new ScheduledTaxContext()) { context.ScheduledTaxes.Add( new ScheduledTax { ScheduledTaxId = Guid.NewGuid(), Municipality = enumerable.FirstOrDefault(), TaxType = enumerable.Skip(1).FirstOrDefault(), Rate = double.Parse(enumerable.Skip(2).FirstOrDefault()), From = DateTime.Parse(enumerable.Skip(3).FirstOrDefault()), To = DateTime.Parse(enumerable.Skip(4).FirstOrDefault()) }); context.SaveChanges(); } return("Operation successful"); }
private string Import(IEnumerable <string> enumerable) { if (File.Exists(enumerable.First())) { return($"File not exist in path \"{enumerable.First()}\""); } IEnumerable <ScheduledTax> records = null; using (var reader = new StreamReader(enumerable.First())) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { records = csv.GetRecords <ScheduledTax>(); } using (var context = new ScheduledTaxContext()) { context.ScheduledTaxes.AddRange(records); context.SaveChanges(); } return("Operation successful"); }