// GET: api/PersonApi public List <Person> GetList() { Person obj = new Person(); Repository.PersonRepository cl = new Repository.PersonRepository(); List <Person> p = cl.Getlist(obj); return(p); }
public static void SeedDbForExcelData(Entities.RepositoryContext context, string fileName, Entities.Models.Person person) { var roundRepository = new Repository.RoundRepository(context); var personRepository = new Repository.PersonRepository(context); var locationRepository = new Repository.LocationRepository(context); // do nothing if current person exists if (personRepository.FindByCondition(s => s.Name == person.Name).ToList().Count > 0) { return; } var allSavedLocations = locationRepository.FindAll().ToList(); using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2016; personRepository.Create(person); using (FileStream fs = File.OpenRead(Path.Combine(@"..\\ExcelLoader\\data\\", fileName))) { IWorkbook wb = application.Workbooks.Open(fs); IWorksheet ws = wb.Worksheets[0]; var usedRowsLength = ws.UsedRange.Rows.Length; for (int i = 0; i < usedRowsLength; i++) { if (i == 0) { continue; } if (string.IsNullOrEmpty((string)ws.Range["A" + (i + 1)].Value2)) { break; } DateTime actualDate = getDate((string)ws.Range["A" + (i + 1)].Value2, (string)ws.Range["C" + (i + 1)].Value2, (string)ws.Range["E" + (i + 1)].Value2.ToString(), (i + 1)); Console.WriteLine("date is: " + actualDate.ToString()); double routeLenght = (double)ws.Range["G" + (i + 1)].Value2; string locationName = (string)ws.Range["H" + (i + 1)].Value2; var location = allSavedLocations.SingleOrDefault(l => { return(l.Name == locationName); }); //do not add location if not known if (location == null && !string.IsNullOrEmpty(locationName.TrimStart().TrimEnd())) { location = new Location { Name = locationName }; locationRepository.Create(location); allSavedLocations.Add(location); } var round = new Entities.Models.Round { TotalKilometers = routeLenght, SkiStyle = 1, ActionTime = actualDate, Person = person, Location = location }; roundRepository.CreateRound(round); } } } }