public ActionResult AssignCourseToTrainer(TrainerCoursesViewModel model) { var IfCourseExist = _context.TrainerCourses.SingleOrDefault(t => t.TrainerId == model.TrainerId && t.CourseId == model.CourseId); if (IfCourseExist != null) { var viewModel = new TrainerCoursesViewModel() { Trainers = _context.Users.OfType <Trainer>().ToList(), Courses = _context.Courses.ToList() }; ViewBag.message = "This Course had been assigned to this trainer"; return(View(viewModel)); } else { var trainerCourses = new TrainerCourses() { TrainerId = model.TrainerId, CourseId = model.CourseId }; _context.TrainerCourses.Add(trainerCourses); _context.SaveChanges(); return(RedirectToAction("AllCourseOfTrainer", "TrainerRelated", new { trainerId = model.TrainerId })); } }
public ActionResult ReassignedTrainerToCourse(TrainerCoursesViewModel model) { var trainerCourse = _context.TrainerCourses.SingleOrDefault(t => t.Id == model.TrainerCourse.Id); trainerCourse.CourseId = model.TrainerCourse.CourseId; _context.SaveChanges(); return(RedirectToAction("AllCourseOfTrainer", "TrainerRelated", new { trainerId = model.TrainerId })); }
public ActionResult AssignCourseToTrainer() { var viewModel = new TrainerCoursesViewModel() { Trainers = _context.Users.OfType <Trainer>().ToList(), Courses = _context.Courses.ToList() }; return(View(viewModel)); }
public ActionResult ReassignedTrainerToCourse(int Id) { var trainerCourse = _context.TrainerCourses.SingleOrDefault(t => t.Id == Id); var trainerId = trainerCourse.TrainerId; TrainerCoursesViewModel model = new TrainerCoursesViewModel { TrainerCourse = trainerCourse, Courses = _context.Courses.ToList(), TrainerId = trainerId }; return(View(model)); }