public async Task HandleAsync(Employee employee)
        {
            if (!await _validator.ValidateAsync(employee))
            {
                return;
            }

            await _repository.InsertAsync(employee);

            await _unitOfWork.CommitAsync();

            await _mailMessageSender.Send(employee);
        }
示例#2
0
        public async Task <Guid> AddEmployee(EmployeeDto employee)
        {
            if (await _employeeContext.CpfExists(employee.Cpf))
            {
                throw new Exception("Employee already exists.");
            }

            var mappedEmployee   = MapEmployee(employee);
            var validationResult = await _employeeValidator.ValidateAsync(mappedEmployee, CancellationToken.None);

            if (validationResult.IsValid)
            {
                var result = await _employeeContext.InsertEmployee(mappedEmployee);

                return(result);
            }

            throw new Exception("Invalid employee data.");
        }