Beispiel #1
0
        private static void LoadFile(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName))
            {
                var csv = new CsvReader(sr);
                while (csv.Read())
                {
                    //Import Customer(Account and Parent)
                    int accountId = ImportCustomer(csv);

                    //ClassInfo
                    ClassInfo classInfo = new ClassInfo();
                    classInfo.FromCsv(csv);

                    using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
                    {
                        ClassInfoRepo repo = new ClassInfoRepo(dbContext);

                        repo.Add(classInfo);

                        try
                        {
                            //Save to DB
                            dbContext.SaveChanges();
                        }
                        catch (DbEntityValidationException)
                        {
                            throw;
                        }
                    }
                }
            }
        }