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));
        }
Beispiel #2
0
        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));
        }