public async Task <IActionResult> Edit(int id, [Bind("TrainingId,Title,Description,StartDate,EndDate")] Training training) { if (id != training.TrainingId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(training); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrainingExists(training.TrainingId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(training)); }
public async Task <IActionResult> Edit(int id, [Bind("DepartmentId,Name")] Department department) { if (id != department.DepartmentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(department); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.DepartmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Edit(int id, EmployeeEditViewModel model) { if (id != model.Employee.EmployeeId) { return(NotFound()); } if (ModelState.IsValid) { try { // Update employee information _context.Update(model.Employee); // Remove all employee training sessions first List <EmployeeTraining> sessions = await _context.EmployeeTraining .Where(t => t.EmployeeId == id).ToListAsync(); foreach (var session in sessions) { _context.Remove(session); } // Add selected training sessions if (model.SelectedSessions.Count > 0) { foreach (int sessionId in model.SelectedSessions) { EmployeeTraining session = new EmployeeTraining() { EmployeeId = id, TrainingId = sessionId }; await _context.AddAsync(session); } } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(model.Employee.EmployeeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }