public async Task <IActionResult> Create([FromBody] Employee employee)
        {
            if (employee == null)
            {
                return(BadRequest());
            }

            await _employeesRepository.AddEmployeeAsync(employee);

            return(Created($"/employees/{employee.Id}", employee));
        }
示例#2
0
        public async Task <Unit> Handle(AddEmployeeCommandModel request, CancellationToken cancellationToken)
        {
            var employee    = new Core.Entities.Employee(request.FirstName, request.LastName, request.DateOfBirth, request.Address);
            var jobPosition = await positionRepository.GetJobPositionAsync(request.Position);

            if (jobPosition == null)
            {
                throw new ManagerException(ErrorsMessage.JobPositionDoesNotExist);
            }

            var employeeJobPositionModel = new EmployeeJobPosition(jobPosition, employee);
            await employeeJpRepository.AddEmployeeJobPositionAsync(employeeJobPositionModel);

            employee.MainRole = request.Position;
            employee.Positions.Add(employeeJobPositionModel);

            await employeesRepository.AddEmployeeAsync(employee);

            await employeesRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }