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 }); } }
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); }
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); }
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); }
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); } }
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); } }