public ActionResult AssignTraining(int id, AssignTrainingViewModel TrainingViewModel)
        {
            TrainingViewModel.Employee = GetEmployeeWTrainingById(id);
            try
            {
                using (SqlConnection conn = Connection)
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        if (TrainingViewModel.Employee != null)
                        {
                            var TrainingProgramIdsToDelete = TrainingViewModel.Employee.AllTrainingPrograms.Select(tp => tp.Id).ToList();
                            foreach (int oldTrainingId in TrainingProgramIdsToDelete)
                            {
                                cmd.CommandText = @"DELETE FROM EmployeeTraining 
                                            WHERE EmployeeId = @id AND TrainingProgramId = @trainingId;";
                                cmd.Parameters.Clear();
                                cmd.Parameters.Add(new SqlParameter("@id", id));
                                cmd.Parameters.Add(new SqlParameter("@trainingId", oldTrainingId));


                                cmd.ExecuteNonQuery();
                            }
                        }
                        foreach (int trainingId in TrainingViewModel.SelectedTrainingIds)
                        {
                            cmd.CommandText = @"INSERT INTO EmployeeTraining(EmployeeId, TrainingProgramId)
                                                    VALUES (@id, @TrainingProgramId);";

                            cmd.Parameters.Clear();
                            cmd.Parameters.Add(new SqlParameter("@id", id));
                            cmd.Parameters.Add(new SqlParameter("@TrainingProgramId", trainingId));

                            cmd.ExecuteNonQuery();
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // GET: Employee/AssignTraining
        public ActionResult AssignTraining(int id)
        {
            Employee employee = GetEmployeeWTrainingById(id);

            if (employee != null)
            {
                var viewModel = new AssignTrainingViewModel()
                {
                    Employee            = employee,
                    AllTrainingPrograms = GetAvailableTrainings(id),
                    SelectedTrainingIds = employee.AllTrainingPrograms.Select(tp => tp.Id).ToList()
                };
                return(View(viewModel));
            }
            else
            {
                var viewModel = new AssignTrainingViewModel()
                {
                    AllTrainingPrograms = GetAvailableTrainings(id),
                };
                return(View(viewModel));
            }
        }