예제 #1
0
 public void CreateClass(Class newClass)
 {
     using (var db = new Database(_connectionName))
     {
         db.Insert("Class", "ID", new { Name = newClass.Name, Location = newClass.Location, TeacherName = newClass.TeacherName });
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        public ActionResult CreateClass(Class model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repository.CreateClass(model);
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View(model);
        }
예제 #4
0
        public ActionResult EditClass(Class updatedClass)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repository.UpdateClass(updatedClass);
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return View(updatedClass);
        }
예제 #5
0
 public void UpdateClass(Class updatedClass)
 {
     using (var db = new Database(_connectionName))
     {
         db.Update("Class", "ID", new { Name = updatedClass.Name, Location = updatedClass.Location, TeacherName = updatedClass.TeacherName }, updatedClass.Id);
     }
 }
예제 #6
0
        public void SaveClass(Class updatedClass)
        {
            using (var db = new Database(_connectionName))
            {
                var sql = Sql.Builder.Append("DELETE FROM dbo.Student WHERE ClassId = @0", updatedClass.Id);
                db.Execute(sql);

                foreach (var student in updatedClass.Students)
                {
                    CreateStudent(student);
                }

                db.Update("Class", "ID", new { Name = updatedClass.Name, Location = updatedClass.Location, TeacherName = updatedClass.TeacherName }, updatedClass.Id);
            }
        }