public void MethodToTest(int id, string firstName, string lastName, DateTime enrollmentDate)
        {
            var student = _context.Students.Add(new Student {
                ID = id, FirstMidName = firstName, LastName = lastName, EnrollmentDate = enrollmentDate
            });

            _context.SaveChanges();
        }
Beispiel #2
0
 public ActionResult Create([Bind(Include = "LastName,FirstMidName,HireDate,OfficeAssignment")] Instructor instructor, string[] selectedCourses)
 {
     if (selectedCourses != null)
     {
         instructor.Courses = new List <Course>();
         foreach (var course in selectedCourses)
         {
             var courseToAdd = db.Courses.Find(int.Parse(course));
             instructor.Courses.Add(courseToAdd);
         }
     }
     if (ModelState.IsValid)
     {
         db.Instructors.Add(instructor);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     PopulateAssignedCourseData(instructor);
     return(View(instructor));
 }
Beispiel #3
0
        public Student AddStudent(Student student)
        {
            var addedStudent = _context.Students.Add(new Student()
            {
                Grade = student.Grade,
                Name  = student.Name
            });

            _context.SaveChanges();

            return(addedStudent);
        }
        public ActionResult EditPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var enrollmentToUpdate = _db.Enrollments.Find(id);

            if (TryUpdateModel(enrollmentToUpdate, "", new string[] { "Grade" }))
            {
                try {
                    _db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException /* dex */) {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            return(View(enrollmentToUpdate));
        }
Beispiel #5
0
 public bool CreateGroup(Group group)
 {
     try
     {
         db.Groups.Add(group);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }