public ActionResult AssignCourseToTrainee(TraineeCourseViewModel model)
        {
            var IfCourseExist = _context.TraineeCourses.SingleOrDefault(t => t.TraineeId == model.TraineeId && t.CourseId == model.CourseId);

            if (IfCourseExist != null)
            {
                var viewModel = new TraineeCourseViewModel()
                {
                    Trainees = _context.Users.OfType <Trainee>().ToList(),
                    Courses  = _context.Courses.ToList()
                };
                ViewBag.message = "This Course had been assigned to this trainee";
                return(View(viewModel));
            }
            else
            {
                var traineeCourses = new TraineeCourses()
                {
                    TraineeId = model.TraineeId,
                    CourseId  = model.CourseId
                };
                _context.TraineeCourses.Add(traineeCourses);
                _context.SaveChanges();

                return(RedirectToAction("AllCourseOfTrainee", "TraineeRelated", new { traineeId = model.TraineeId }));
            }
        }
        public ActionResult AssignCourseToTrainee(int CourseId, AssignTraineeViewModel model)
        {
            var assignCourse = new TraineeCourses();

            assignCourse.CourseId  = model.CourseId;
            assignCourse.TraineeId = model.TraineeId;
            if (!_context.TraineeCourses
                .Where(t => t.CourseId == model.CourseId)
                .Select(t => t.TraineeId)
                .Contains(model.TraineeId))
            {
                _context.TraineeCourses.AddOrUpdate(assignCourse);
                _context.SaveChanges();
                ViewBag.Message = "Assign successfully";
            }
            else
            {
                ModelState.AddModelError("Validation", "This trainee has been assigned already");
            }

            return(RedirectToAction("DetailCourse", "Staff", new { @id = CourseId }));
        }