Exemple #1
0
 public void CreateStudent(Student student)
 {
     using (var db = new Database(_connectionName))
     {
         db.Insert("Student", "ID", new { FirstName = student.FirstName, LastName = student.LastName, Age = student.Age, GPA = student.GPA, ClassId = student.ClassId });
     }
 }
        public void CannotAddStudentWithDuplicateSurname()
        {
            var newStudent = new Student() {Age = 20, ClassId = 1, FirstName = "Varun", LastName = "Bhargava", GPA = 3.2m};
            var existingStudents = new List<Student>();
            existingStudents.Add(new Student() { Age = 20, ClassId = 1, FirstName = "Varun 1", LastName = "Bhargava 1", GPA = 3.2m });
            existingStudents.Add(new Student() { Age = 30, ClassId = 3, FirstName = "Varun 2", LastName = "Bhargava 3", GPA = 3.2m });
            existingStudents.Add(new Student() { Age = 40, ClassId = 4, FirstName = "Varun 3", LastName = "Bhargava", GPA = 3.2m });

            var myClass = new Class() {Id = 1, Location = "Somewhere", Name = "Someclass"};
            myClass.AddStudent(newStudent, existingStudents);
        }
Exemple #3
0
        public void AddStudent(Student newStudent, List<Student> allExistingStudents)
        {
            if (Students == null)
                Students = new List<Student>();

            if (allExistingStudents.Any(student => student.LastName.ToLower() == newStudent.LastName.ToLower()))
            {
                throw new Exception(string.Format("A Student with the surname {0} already exists.", newStudent.LastName));
            }

            Students.Add(newStudent);
        }
        public ActionResult CreateStudent(Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var existingClass = _repository.GetClass(student.ClassId);
                    var allStudents = _repository.GetAllStudents();

                    existingClass.AddStudent(student, allStudents);

                    _repository.SaveClass(existingClass);
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View(student);
        }
 public ActionResult CreateStudent(int classId)
 {
     var student = new Student() {ClassId = classId};
     return View(student);
 }
        public ActionResult EditStudent(Student updatedStudent)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repository.UpdateStudent(updatedStudent);
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View(updatedStudent);
        }
Exemple #7
0
 public void UpdateStudent(Student updatedStudent)
 {
     using (var db = new Database(_connectionName))
     {
         db.Update("Student", "ID", new { FirstName = updatedStudent.FirstName, LastName = updatedStudent.LastName, Age = updatedStudent.Age, GPA = updatedStudent.GPA }, updatedStudent.Id);
     }
 }