public async Task <IActionResult> Edit(int id, [Bind("DepartmentID,DepartmentName")] Department department) { if (id != department.DepartmentID) { return(NotFound()); } if (ModelState.IsValid) { try { var command = new EditDepartmentCommand(department); var handler = CommandHandlerFactory.Build(command); handler.Execute(_context); 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, [Bind("EmployeeID,DepartmentID,Surname,Name,Patronymic,DateOfBirth")] Employee employee) { if (id != employee.EmployeeID) { return(NotFound()); } if (ModelState.IsValid) { try { var command = new EditEmployeeCommand(employee); var handler = CommandHandlerFactory.Build(command); handler.Execute(_context); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.EmployeeID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = new SelectList(_context.Department, "DepartmentID", "DepartmentID", employee.DepartmentID); return(View(employee)); }
public async Task <IActionResult> Create([Bind("DepartmentID,DepartmentName")] Department department) { if (ModelState.IsValid) { var command = new CreateDepartmentCommand(department); var handler = CommandHandlerFactory.Build(command); handler.Execute(_context); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create([Bind("EmployeeID,DepartmentID,Surname,Name,Patronymic,DateOfBirth")] Employee employee) { if (ModelState.IsValid) { var command = new CreateEmployeeCommand(employee); var handler = CommandHandlerFactory.Build(command); handler.Execute(_context); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = new SelectList(_context.Department, "DepartmentID", "DepartmentID", employee.DepartmentID); return(View(employee)); }