Esempio n. 1
0
        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 }));
            }
        }
Esempio n. 2
0
        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 }));
        }
Esempio n. 3
0
        public ActionResult AssignCourseToTrainer()
        {
            var viewModel = new TrainerCoursesViewModel()
            {
                Trainers = _context.Users.OfType <Trainer>().ToList(),
                Courses  = _context.Courses.ToList()
            };

            return(View(viewModel));
        }
Esempio n. 4
0
        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));
        }