public void testUpdate()
        {
            // Arrange
            int count = repo.All().Count();

            repo.Add(entity);
            this.repo.SaveChanges();

            Assert.IsEmpty(repo.Get(x => x.Name == n + "alala"));


            Assert.AreEqual(count + 1, repo.All().Count());
            entity.Name += "alala";


            // Act
            repo.Update(entity);
            repo.SaveChanges();

            // Assert

            Assert.NotNull(repo.Get(x => x.Name == n + "alala"));

            this.repo.HardDelete(entity);
            this.repo.SaveChanges();
        }
        public void When_GettingAllStudents_Then_AllTheStudentsShouldBeLoaded()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository = new StudentRepository(sut);
                var user1      = new Student()
                {
                    Id        = Guid.NewGuid(),
                    FirstName = "Mos",
                    LastName  = "Craciun"
                };
                repository.Add(user1);

                var user2 = new Student()
                {
                    Id        = Guid.NewGuid(),
                    FirstName = "test",
                    LastName  = "student"
                };
                repository.Add(user2);

                //Act
                var result = repository.GetAll();

                //Assert
                result.Count().Should().Be(2);
            });
        }
        public void SetUp()
        {
            Student student = new Student
            {
                Id            = "heuiheufh",
                FirstName     = "FirstStudent",
                LastName      = "Test",
                Email         = "*****@*****.**",
                StudentNumber = "SXXXXXX0"
            };

            Repository.Add(student);
        }
Example #4
0
        public async Task TestAddNonNullEntity()
        {
            // Arrange
            var options = TestUtilities.BuildTestDbOptions();

            var testEntity = new Student();

            await using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureCreated();

                var repository = new StudentRepository(context);

                Assert.Empty(context.Student);

                // Act
                repository.Add(testEntity);

                context.SaveChanges();
            }

            // Assert
            await using (var context = new ApplicationDbContext(options))
            {
                Assert.Single(context.Student);

                context.Database.EnsureDeleted();
            }
        }
Example #5
0
        public ActionResult Add(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();

                foreach (var id in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(id));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

                StudentRepository.Add(studentVM.Student);

                return(RedirectToAction("List"));
            }
            else
            {
                studentVM.SetCourseItems(CourseRepository.GetAll());
                studentVM.SetMajorItems(MajorRepository.GetAll());

                return(View(studentVM));
            }
        }
Example #6
0
        public void CanReadStudent()
        {
            // Arange
            var dbFactory         = new DatabaseFactory();
            var studentRepository = new StudentRepository(dbFactory);
            var unitOfWork        = new UnitOfWork(dbFactory);

            studentRepository.Add(new STUDENT
            {
                STUDENT_INTERNAL_ID = "1",
                DISCOUNT            = 10.2M,
                PAYMENTTYPE         = "Rate",
                PERSON = new PERSON {
                    FIRSTNAME = "Jovan",
                    LASTNAME  = "Jovanovic",
                    EMAIL     = "*****@*****.**",
                    TELEPHONE = "0644985665"
                }
            });

            unitOfWork.Commit();

            // Act
            var student = studentRepository.Get(s => s.STUDENT_INTERNAL_ID == "1");

            // Assert
            Assert.IsNotNull(student, "student doesn't exist");
        }
Example #7
0
        public ActionResult Add(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();

                foreach (var id in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(id));
                }

                if (studentVM.Student.Courses.Count == 0)
                {
                    ModelState.AddModelError("Courses", "Please select at least one course. ");
                    return(View(studentVM));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

                if (string.IsNullOrEmpty(studentVM.Student.Major.MajorName))
                {
                    ModelState.AddModelError("MajorName", "Please select a major.");
                    return(View(studentVM));
                }

                StudentRepository.Add(studentVM.Student);

                return(RedirectToAction("List"));
            }
            studentVM.SetCourseItems(CourseRepository.GetAll());
            studentVM.SetMajorItems(MajorRepository.GetAll());
            studentVM.SetStateItems(StateRepository.GetAll());
            return(View(studentVM));
        }
Example #8
0
        public async Task <ActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                _studentRepository.Add(new Student
                {
                    ClassName            = ClassName,
                    FirstName            = FirstName,
                    LastClassCompleted   = LastClassCompleted,
                    LastName             = LastName,
                    StudentId            = StudentId,
                    StartDate            = StartDate,
                    LastClassCompletedOn = LastClassCompletedOn
                });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(Page());
            }

            return(RedirectToPage("Index", new { message = $"Student {FirstName} with ID {StudentId} was saved" }));
        }
 public ActionResult Add(StudentVM studentVM)
 {
     studentVM.PersonalDetailsVM.Courses = new List <Course>();
     foreach (var id in studentVM.PersonalDetailsVM.SelectedCourseIds)
     {
         studentVM.PersonalDetailsVM.Courses.Add(CourseRepository.Get(id));
     }
     if (ModelState.IsValid)
     {
         var student = new Student();
         student.FirstName = studentVM.PersonalDetailsVM.FirstName;
         student.LastName  = studentVM.PersonalDetailsVM.LastName;
         student.GPA       = studentVM.PersonalDetailsVM.GPA;
         student.Major     = MajorRepository.Get(studentVM.PersonalDetailsVM.MajorId);
         student.Courses   = studentVM.PersonalDetailsVM.Courses;
         student.Address   = new Address();
         StudentRepository.Add(student);
         return(RedirectToAction("List"));
     }
     else
     {
         studentVM.PersonalDetailsVM.SetCourseItems(CourseRepository.GetAll());
         studentVM.PersonalDetailsVM.SetMajorItems(MajorRepository.GetAll());
         return(View(studentVM));
     }
 }
        public void EnrollStudentIntoCourse_CourseNotFound_ReturnsFalse()
        {
            var studentRepository = new StudentRepository(Context);

            var student = new Student()
            {
                FirstName = "Mikesh",
                LastName  = "Mistry"
            };

            //add a student
            studentRepository.Add(student);

            //find the newly added teacher
            var enrollingStudent = studentRepository.Find(student => student.FirstName == "Mikesh")
                                   .FirstOrDefault();

            //found the student
            if (enrollingStudent != null)
            {
                //assign a student to a course that does not exist
                var enrolledStudent = courseRepository.EnrollStudentIntoCourse(enrollingStudent.StudentId, 1234);

                //should return false indicating student was not enrolled in the course
                Assert.IsFalse(enrolledStudent);
            }
        }
        public ActionResult Edit(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();

                foreach (var id in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(id));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

                StudentRepository.Delete(studentVM.Student.StudentId);
                StudentRepository.Add(studentVM.Student);

                return(RedirectToAction("List"));
            }
            else
            {
                var viewModel = new StudentVM();
                viewModel.Student = StudentRepository.Get(studentVM.Student.StudentId);
                viewModel.SetCourseItems(CourseRepository.GetAll());
                viewModel.SetMajorItems(MajorRepository.GetAll());
                viewModel.SetStateItems(StateRepository.GetAll());

                if (!(viewModel.Student.Courses == null))
                {
                    viewModel.SelectedCourseIds = viewModel.Student.Courses.Select(s => s.CourseId).ToList();
                }

                return(View(viewModel));
            }
        }
Example #12
0
        public ActionResult Add(StudentVM studentVM)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StudentVM();
                viewModel.Student.Courses = new List <Course>();
                viewModel.SetCourseItems(CourseRepository.GetAll());
                viewModel.SetMajorItems(MajorRepository.GetAll());
                viewModel.SetStateItems(StateRepository.GetAll());
                return(View("Add", viewModel));
            }
            studentVM.Student.Courses = new List <Course>();


            foreach (var id in studentVM.CourseItems.Where(m => m.Selected))
            {
                studentVM.Student.Courses.Add(CourseRepository.Get(int.Parse(id.Value)));
            }

            studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

            StudentRepository.Add(studentVM.Student);

            return(RedirectToAction("List"));
        }
        public ActionResult Add(StudentVM studentVM)
        {
            //if(studentVM.Student.Major.MajorId > 0)
            //{
            //    studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);
            //}
            //if (ModelState["Student.Major.MajorName"].Errors.Count == 1)
            //{
            //    ModelState["Student.Major.MajorName"].Errors.Clear();
            //}
            //if (ModelState["Student.Courses"].Errors.Count == 1)
            //{
            //    ModelState["Student.Courses"].Errors.Clear();
            //}
            if (!ModelState.IsValid)
            {
                studentVM.SetCourseItems(CourseRepository.GetAll());
                studentVM.SetMajorItems(MajorRepository.GetAll());
                return(View(studentVM));
            }

            studentVM.Student.Courses = new List <Course>();
            foreach (var id in studentVM.SelectedCourseIds)
            {
                studentVM.Student.Courses.Add(CourseRepository.Get(id));
            }

            studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

            StudentRepository.Add(studentVM.Student);

            return(RedirectToAction("List"));
        }
        public void Execute()
        {
            Console.Clear();
            Console.WriteLine("Add Student");
            Console.WriteLine(ConsoleIO.SeparatorBar);
            Console.WriteLine();

            Student newStudent = new Student();

            newStudent.FirstName = ConsoleIO.GetRequiredStringFromUser("First Name: ");
            newStudent.LastName  = ConsoleIO.GetRequiredStringFromUser("Last Name: ");
            newStudent.Major     = ConsoleIO.GetRequiredStringFromUser("Major: ");
            newStudent.GPA       = ConsoleIO.GetRequiredDecimalFromUser("GPA: ");

            Console.WriteLine();
            ConsoleIO.PrintStudentListHeader();
            Console.WriteLine(ConsoleIO.StudentLineFormat, newStudent.LastName + ", " + newStudent.FirstName, newStudent.Major, newStudent.GPA);

            Console.WriteLine();
            if (ConsoleIO.GetYesNoAnswerFromUser("Add the following information") == "Y")
            {
                StudentRepository repo = new StudentRepository(Settings.FilePath);
                repo.Add(newStudent);
                Console.WriteLine("Student Added!");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Add Cancelled");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
        public void CanAddStudentToFile()
        {
            StudentRepository repo = new StudentRepository(_filePath);

            Student newStudent = new Student
            {
                FirstName = "Testy",
                LastName  = "Tester",
                Major     = "Research",
                GPA       = 3.2M
            };

            repo.Add(newStudent);

            List <Student> students = repo.List();

            Assert.AreEqual(5, students.Count());

            Student check = students[4];

            Assert.AreEqual("Testy", check.FirstName);
            Assert.AreEqual("Tester", check.LastName);
            Assert.AreEqual("Research", check.Major);
            Assert.AreEqual(3.2M, check.GPA);
        }
Example #16
0
        public JsonResult Save(Dictionary <string, string> transactions, StudentModel student, int periodGroupId)
        {
            var studentId = student.StudentId;

            try
            {
                SaveResult studentResult = new SaveResult {
                    Status = "OK"
                };
                using (TransactionScope scope = new TransactionScope())
                {
                    if (studentId <= 0)
                    {
                        studentResult = _studentRepository.Add(student);
                        studentId     = studentResult.Id;
                    }

                    if (studentResult.Status == "OK")
                    {
                        var periodGradeStudentResult = this.SaveGradeGroup(studentId, periodGroupId);

                        if (periodGradeStudentResult.Status == "OK")
                        {
                            var configurationResult = this.SaveStudentConfiguration(transactions, periodGradeStudentResult.Id);

                            if (configurationResult.Status != "OK")
                            {
                                throw new Exception(configurationResult.Message);
                            }
                        }
                        else
                        {
                            throw new Exception(periodGradeStudentResult.Message);
                        }
                    }
                    else
                    {
                        throw new Exception(studentResult.Message);
                    }


                    scope.Complete();
                }

                return(Json(new
                {
                    StudentId = studentId,
                    Message = "Student Configuration was created",
                    Status = "OK"
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Message = ex.Message,
                    Status = "ERROR"
                }, JsonRequestBehavior.AllowGet));
            }
        }
Example #17
0
        public void AddGrade()
        {
            //create the student
            var newStudent = new Student()
            {
                FirstName = "Mikesh",
                LastName  = "Mistry"
            };


            //add the student
            studentRepository.Add(newStudent);

            //Find the student
            var foundStudent = studentRepository.GetAll().ToList();

            //create a course
            var newCourse = new Course()
            {
                Name        = "Introduction To C# Programming",
                Description = "Introduction To C# Programming"
            };

            //add the course to the database
            courseRepository.Add(newCourse);

            //find the course
            var foundCourse = courseRepository.GetAll().ToList();


            //create a new grade
            var newGrade = new Grade()
            {
                Student     = newStudent,
                Course      = newCourse,
                LetterGrade = "A+"
            };

            //add the grade
            gradeRepository.Add(newGrade);



            //find the grade
            var foundGrade = gradeRepository.Find(grade => grade.Student.StudentId == foundStudent[0].StudentId &&
                                                  grade.Course.CourseId == foundCourse[0].CourseId

                                                  ).FirstOrDefault();

            //test to see if we found the grade
            Assert.IsNotNull(foundGrade);

            //check are all the values the same
            Assert.AreEqual(foundGrade.Course.CourseId, foundCourse[0].CourseId);
            Assert.AreEqual(foundGrade.Student.StudentId, foundStudent[0].StudentId);
            Assert.AreEqual(foundGrade.LetterGrade, newGrade.LetterGrade);
        }
Example #18
0
        public void Execute(string[] args, StudentRepository studentRepository)
        {
            var name  = args[1];
            var age   = int.Parse(args[2]);
            var grade = double.Parse(args[3]);

            studentRepository.Add(name, age, grade);
        }
Example #19
0
        private static bool AlumnoAlta()
        {
            LimpiarConsoleLine();
            Console.WriteLine($"2 - 1) Alta de Alumno. de {nomMenu}");
            Console.WriteLine("Para volver sin guardar alumno entra  *.");

            Console.WriteLine("entra el dni:");
            var  dni     = "";
            bool primera = true;

            ValidationResult <string> vrDni = Student.ValidateDni(dni);

            do
            {
                if (!primera)
                {
                    Console.WriteLine(vrDni.AllErrors);
                }
                dni = Console.ReadLine();
                if (dni == "*")
                {
                    return(false);
                }
                primera = false;
            } while (!(vrDni = Student.ValidateDni(dni)).IsSuccess);


            ValidationResult <string> vrName = EntradaNombre("entra el nombre y apellidos:");


            ValidationResult <int> vrChair = EntraNumSilla("entra el número de silla:");


            if (vrDni.IsSuccess && vrName.IsSuccess && vrChair.IsSuccess)
            {
                var student = new Student
                {
                    Dni         = vrDni.ValidatedResult,
                    Name        = vrName.ValidatedResult,
                    ChairNumber = vrChair.ValidatedResult
                };

                var sr  = student.Save();
                var sr2 = StudentRepository.Add(student);
                if (sr.IsSuccess && sr2.IsSuccess)
                {
                    Console.WriteLine($"alumno guardado correctamente");
                    return(true);
                }
                else
                {
                    Console.WriteLine($"uno o más errores han ocurrido y el alumno no se guardado/actualizado: {sr.AllErrors} {sr2.AllErrors}");
                    return(false);
                }
            }
            return(false);
        }
Example #20
0
 public IActionResult Post(Student student)
 {
     if (student == null)
     {
         return(BadRequest());
     }
     _studentRepository.Add(student);
     return(Ok(student));
 }
        public void addDummy()
        {
            Student newStudent = new Student();

            newStudent.FirstName = "TestFirstName";
            newStudent.LastName  = "TestLastName";
            newStudent.Major     = "TestMajor";
            newStudent.GPA       = 3.0M;
            repo.Add(newStudent);
        }
Example #22
0
        public void Add()
        {
            IStudentRepository studentrepository = new StudentRepository(context, logger);

            Student st1 = new Student();

            studentrepository.Add(st1);

            Assert.IsTrue(st1.Equals(st1));
        }
        public ActionResult Import(string csv)
        {
            // A csv is supplied, try to parse it.
            foreach (string[] d in csv.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                     .Skip(1)
                     .Select(line => line.Split(new[] { ';' })))
            {
                // Try to parse the student number.
                int studentNr;
                if (!int.TryParse(d[1], out studentNr))
                {
                    ModelState.AddModelError("", string.Format("StudentNr '{0}' is geen geldig nummer", d[1]));
                    continue;
                }

                var existing = StudentRepository.GetByStudentNr(studentNr);
                if (existing != null)
                {
                    // Skip existing students.
                    continue;
                }

                // Create a new student from the csv data.
                var student = new Student
                {
                    StudentNr       = studentNr,
                    FirstName       = d[2],
                    LastName        = d[4],
                    SchoolEmail     = d[5].ToLower(),
                    Email           = d[6].ToLower(),
                    ClassId         = int.Parse(d[7]),
                    Telephone       = d[8],
                    StreetNumber    = int.Parse(d[9]),
                    StreetName      = d[10],
                    ZipCode         = d[11],
                    City            = d[12],
                    PreStudy        = d[13],
                    Status          = (Status)Enum.Parse(typeof(Status), d[14]),
                    Active          = d[15] == "1",
                    EnrollDate      = DateTime.Parse(d[16]),
                    LastAppointment = DateTime.Parse(d[16]),
                    BirthDate       = DateTime.Parse(d[17])
                };

                // Generate a password.
                string password = PasswordGenerator.CreateRandomPassword();
                student.Password = Crypto.HashPassword(password);

                // todo: mail

                StudentRepository.Add(student);
            }

            return(View());
        }
Example #24
0
        public void AddOneStudentAndCheckNumberOfStudents()
        {
            var sr            = new StudentRepository();
            var person        = new Teacher("Fredrik");
            var expectedCount = 1;

            sr.Add(person);
            var count = sr.GetNumberOfStudents();

            Assert.AreEqual(expectedCount, count, "Antalet studenter är inte det förväntade");
        }
Example #25
0
        public ActionResult Create(Student student)
        {
            if (!ModelState.IsValid)
            {
                return(View(student));
            }

            repository.Add(student);
            repository.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #26
0
        public ActionResult Add(StudentVM studentVM)
        {
            var viewModel = new StudentVM();

            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());

            studentVM.Student.Courses = new List <Course>();

            foreach (var id in studentVM.SelectedCourseIds)
            {
                studentVM.Student.Courses.Add(CourseRepository.Get(id));
            }

            studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

            if (string.IsNullOrEmpty(studentVM.Student.FirstName))
            {
                ModelState.AddModelError("FistName", "Please enter the students first name.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.LastName))
            {
                ModelState.AddModelError("LastName", "Please enter the students last name.");
            }

            if (studentVM.Student.GPA > 4.0M || studentVM.Student.GPA < 0.0M)
            {
                ModelState.AddModelError("GPA", "Please enter the GPA between 0.0 and 4.0.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.Address.Street1))
            {
                ModelState.AddModelError("Student.Address.Street1", "You must provide atleast one street address.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.Address.City))
            {
                ModelState.AddModelError("Student.Address.City", "Please enter the city.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.Address.PostalCode))
            {
                ModelState.AddModelError("Student.Address.PostalCode", "Please enter the postal code.");
            }

            if (ModelState.IsValid)
            {
                StudentRepository.Add(studentVM.Student);
                return(RedirectToAction("List"));
            }
            return(View(viewModel));
        }
        public string Save(Student student)
        {
            bool cityExist = cityRepository.CityExists(student.City);

            if (!cityExist)
            {
                throw new ArgumentException("City Does not Exists");
            }

            return(studentReository.Add(student));
        }
Example #28
0
        public void TestSayGoodMorning()
        {
            var sr            = new StudentRepository();
            var person        = new Teacher("Fredrik");
            var expectedCount = 1;

            sr.Add(person);
            var result = sr.SayGoodMorning();

            Assert.AreEqual(expectedCount, result.Count);
        }
Example #29
0
        public IHttpActionResult PostStudent(Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Add(student);

            return(CreatedAtRoute("DefaultApi", new { id = student.Id }, student));
        }
Example #30
0
        public JsonResult Add(StudentModel student)
        {
            using (var studentRepository = new StudentRepository())
            {
                studentRepository.Add(new StudentDTO {
                    Name = student.Name, Surname = student.Surname, Number = student.Number, ClassId = student.ClassId
                });
            }

            return(Json("ok"));
        }