public ActionResult CreateInstructor() { var viewModel = new InstructorFormViewModel { Departments = _context.Departments.ToList() }; return(View(viewModel)); }
public ActionResult CreateInstructor(InstructorFormViewModel viewModel) { var instructor = new Instructor { InstructorName = viewModel.InstructorName, Designation = viewModel.Designation, DepartmentId = viewModel.Department }; _context.Instructors.Add(instructor); _context.SaveChanges(); return(RedirectToAction("Display", "Instructors")); }
public ActionResult EditInstructor(int id) { var userId = User.Identity.GetUserId(); var instructor = _context.Instructors.Single(s => s.Id == id); var viewModel = new InstructorFormViewModel { Id = instructor.Id, InstructorName = instructor.InstructorName, Designation = instructor.Designation, Departments = _context.Departments.ToList() }; return(View("CreateInstructor", viewModel)); }
public ActionResult Update(InstructorFormViewModel viewModel) { //var genre = _context.Genres.Single(g => g.Id == viewModel.Genre); if (!ModelState.IsValid) { viewModel.Departments = _context.Departments.ToList(); return(View("CreateInstructor", viewModel)); } // var course = _context.Courses.Single(c => c.Id == viewModel.Id); var instructor = _context.Instructors.Single(c => c.Id == viewModel.Id); instructor.InstructorName = viewModel.InstructorName; instructor.Designation = viewModel.Designation; instructor.DepartmentId = viewModel.Department; _context.SaveChanges(); return(RedirectToAction("Display", "Instructors")); }