public ActionResult Assign(int id, EmployeeTrainingProgramViewModel model) { try { // TODO: Add update logic here using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"INSERT INTO EmployeeTraining (EmployeeId, TrainingProgramId) VALUES (@employeeId, @trainingProgramId)"; cmd.Parameters.AddWithValue("@employeeId", id); cmd.Parameters.AddWithValue("@trainingProgramId", model.TrainingProgramId); cmd.ExecuteNonQuery(); } } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
// GET: Employees/Assign/5 public ActionResult Assign(int id) { Employee employee = GetSingleEmployee(id); List <TrainingProgram> trainingPrograms = GetAllTrainingPrograms(); var viewModel = new EmployeeTrainingProgramViewModel(employee, trainingPrograms); return(View(viewModel)); }
// Get Training Programs public ActionResult TrainingProgramsForm(int id) { var viewModel = new EmployeeTrainingProgramViewModel(); var employee = GetOneEmplyee(id); var department = GetDepartment(id); viewModel.Employee = employee; viewModel.Department = department; viewModel.TrainingProgramList = trainingList(id); return(View(viewModel)); }