Exemple #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;
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void ClassInfoIntegationTests_AddClass()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ClassInfoRepo repo = new ClassInfoRepo(dbContext);
                repo.Add(new ClassInfo {
                    ClassCategoryId = 1, ClassName = "TestClass", Location = "Trails", ProductCode = "C12345", DateStart = DateTime.Now, DateEnd = DateTime.Now
                });
                try
                {
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    Assert.Fail(exc.EntityValidationErrors.ToString());
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.FindOne(c => c.ClassName == "TestClass");
                Assert.IsNotNull(res);
            }
        }
Exemple #3
0
        //public IEnumerable<ClassCategory> GetAllCategories()
        //{
        //    using (I2LIPrivateClassesDBContext entities = new I2LIPrivateClassesDBContext())
        //    {
        //        //res = entities.ClassInfoes.Include("Orders").Include("ClassCategory").ToList();
        //        var categories = entities.ClassCategories.ToList();
        //        return categories;
        //        //var res = entities.ClassInfoes.ToList();
        //        //return res;
        //    }
        //}

        public ClassInfo GetClassById(int id)
        {
            using (PrivateClassesDBContext entities = new PrivateClassesDBContext())
            {
                return(entities.ClassInfoes.FirstOrDefault(x => x.Id == id));
            }
        }
Exemple #4
0
 public IEnumerable <ClassInfo> GetAllClasses()
 {
     using (PrivateClassesDBContext entities = new PrivateClassesDBContext())
     {
         //var res = entities.ClassInfoes.Include("ClassCategory").ToList();
         var res = entities.ClassInfoes.Include(c => c.ClassCategory).ToList();
         return(res);
     }
 }
Exemple #5
0
 public void ClassInfoIntegationTests_FindUnPaidClasses()
 {
     using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
     {
         ClassInfoRepo    repo = new ClassInfoRepo(dbContext);
         List <ClassInfo> res  = repo.FindMany(c => c.Orders.Where(o => !o.PaymentId.HasValue).Count() > 0).ToList();
         Assert.IsTrue(res != null && res.Count > 0);
     }
 }
        public void ParticipantIntegationTests_GetAllAccounts()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParticipantRepo repo = new ParticipantRepo(dbContext);

                var res = repo.GetAllAccounts();
                Assert.IsTrue(res != null && res.Count > 0);
            }
        }
Exemple #7
0
        public void ClassInfoIntegationTests_GetClassById()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ClassInfoRepo repo = new ClassInfoRepo(dbContext);

                var res = repo.GetClassById(3);
                Assert.IsTrue(res != null && res.ClassCategory != null);
            }
        }
Exemple #8
0
        public void ClassInfoIntegationTests_GetAll()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ClassInfoRepo repo = new ClassInfoRepo(dbContext);

                List <ClassInfo> res = repo.GetAll().ToList();
                Assert.IsTrue(res != null && res.Count > 0);
            }
        }
Exemple #9
0
        public void ClassInfoIntegationTests_GetClassCategoryByKeyword()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ClassInfoRepo repo = new ClassInfoRepo(dbContext);

                var res = repo.GetClassCategoryByKeyword("Party");
                Assert.IsTrue(res != null);
            }
        }
Exemple #10
0
        public void ClassInfoIntegationTests_FindOne()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                GenericRepository <ClassInfo> repo = new GenericRepository <ClassInfo>(dbContext);

                //Calling generic method
                var res = repo.FindOne(x => x.ClassName.ToLower().Contains("Survival") && x.DateStart > new DateTime(2017, 8, 1));
                Assert.IsTrue(res != null);
            }
        }
Exemple #11
0
        public void ClassInfoIntegationTests_FindMany()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                GenericRepository <ClassInfo> repo = new GenericRepository <ClassInfo>(dbContext);

                //Calling generic method
                var res = repo.FindMany(x => x.ClassName.ToLower().Contains("Survival")).ToList();
                Assert.IsTrue(res != null && res.Count > 0);
            }
        }
 public void ParticipantIntegationTests_GetAccountByStudent()
 {
     using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
     {
         ParticipantRepo repo    = new ParticipantRepo(dbContext);
         StudentInfo     student = new StudentInfo()
         {
             LastName = "Skop", FirstName = "Abby", AccountInfoId = 1, Gender = "f"
         };
         var res = repo.GetAllAccounts();
         Assert.IsTrue(res != null && res.Count > 0);
     }
 }
Exemple #13
0
        private static int ImportCustomer(CsvReader csv)
        {
            int accointId = 0;

            //Import Parent
            ParentInfo p = new ParentInfo();

            p.FromCsv(csv);

            //
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParticipantRepo repo = new ParticipantRepo(dbContext);

                //If participant exist
                var existingParent = repo.GetAllParents().FirstOrDefault(x => x.LastName.ToLower() == p.LastName.ToLower() && x.Email == p.Email);
                if (existingParent != null)
                {
                    accointId = existingParent.AccountInfoId;
                    //TODO-1
                    //Update changes
                }
                else
                {
                    //repo.AddAccount(new AccountInfo { LastName = p.LastName, Email = p.Email, DateApplied = DateTime.Now});
                    p.AccountInfo = new AccountInfo {
                        LastName = p.LastName, Email = p.Email, DateApplied = DateTime.Now
                    };
                    repo.AddParent(p);
                }

                try
                {
                    //Save to DB
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    throw new DbEntityValidationException(String.Join("; ", validationErrorMessages));
                }
            }

            return(accointId);
        }
        public void ParticipantIntegationTests_AddStudent()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                List <StudentInfo> validStudents = new List <StudentInfo>()
                {
                    new StudentInfo()
                    {
                        LastName = "Skop", FirstName = "Abby", AccountInfoId = 1, Gender = "f", DateOfBirth = new DateTime(2010, 10, 12)
                    },
                    new StudentInfo()
                    {
                        LastName = "Skop", FirstName = "Max", AccountInfoId = 1, Gender = "m", DateOfBirth = new DateTime(2006, 7, 1)
                    },
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    foreach (var s in validStudents)
                    {
                        repo.AddStudent(s);
                    }
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.GetAllStudents().SingleOrDefault(s => s.LastName == "Skop" && s.FirstName == "Abby");
                Assert.IsNotNull(res);
            }
        }
        public void ParticipantIntegationTests_AddAccount()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                List <AccountInfo> validAccounts = new List <AccountInfo>()
                {
                    new AccountInfo()
                    {
                        LastName = "Skop", Email = "*****@*****.**", DateApplied = DateTime.Now
                    },
                    new AccountInfo()
                    {
                        LastName = "Skop", Email = "*****@*****.**", DateApplied = DateTime.Now
                    }
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    foreach (var a in validAccounts)
                    {
                        repo.AddAccount(a);
                    }
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.GetAllAccounts().SingleOrDefault(a => a.Email == validAccounts[0].Email);
                Assert.IsNotNull(res);
            }
        }
        public void ParticipantIntegationTests_AddParent()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                List <ParentInfo> validParents = new List <ParentInfo>()
                {
                    new ParentInfo()
                    {
                        LastName = "Skop", FirstName = "Serge", AccountInfoId = 1
                    },
                    new ParentInfo()
                    {
                        LastName = "Skop", FirstName = "Lily", AccountInfoId = 1
                    },
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    foreach (var p in validParents)
                    {
                        repo.AddParent(p);
                    }
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.GetAllParents().SingleOrDefault(p => p.LastName == "Skop" && p.FirstName == "Serge");
                Assert.IsNotNull(res);
            }
        }
        public void ParticipantIntegationTests_AddSecondParentWithExistingAccount()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParentInfo parent_2 = new ParentInfo()
                {
                    LastName = "Doe", FirstName = "Jane", Email = "*****@*****.**"
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    //Get Account
                    var allAccounts = repo.GetAllAccounts();
                    var a           = allAccounts.SingleOrDefault(x => x.LastName == parent_2.LastName && x.Email.Trim() == parent_2.Email);
                    Assert.IsNotNull(a, "Account not found");
                    parent_2.AccountInfo = a;
                    //repo.AddParent(parent_2);
                    //dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var parentRes_2 = repo.GetAllParents().SingleOrDefault(p => p.LastName.Trim() == parent_2.LastName && p.FirstName.Trim() == parent_2.FirstName);
                Assert.IsNotNull(parentRes_2, "Parent 2");

                Assert.IsNotNull(parentRes_2.AccountInfo, "AccountInfo is NULL");
                Assert.IsTrue(parentRes_2.AccountInfoId > 0, "AccountId");
            }
        }
        public void ParticipantIntegationTests_AddParentWithAccount()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParentInfo parent_1 = new ParentInfo()
                {
                    LastName = "Doe", FirstName = "John", Email = "*****@*****.**"
                };
                AccountInfo a = new AccountInfo {
                    LastName = parent_1.LastName, Email = parent_1.Email
                };
                parent_1.AccountInfo = a;

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    repo.AddParent(parent_1);
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var parentRes_1 = repo.GetAllParents().SingleOrDefault(p => p.LastName == parent_1.LastName && p.FirstName == parent_1.FirstName);
                Assert.IsNotNull(parentRes_1, "Parent 1");

                Assert.IsNotNull(parentRes_1.AccountInfo, "AccountInfo is NULL");
                Assert.IsTrue(parentRes_1.AccountInfoId > 0, "AccountId");
            }
        }
Exemple #19
0
 public ClassInfoRepo(PrivateClassesDBContext dbContext) :
     base(dbContext)
 {
 }
Exemple #20
0
 public ParticipantRepo(PrivateClassesDBContext dbContext) :
     base(dbContext)
 {
 }