Ejemplo n.º 1
0
        public async Task <IActionResult> RegisterEmployee([FromBody] RegisterEmployeeCommandRequest commandRequest)
        {
            var commandResponse = await mediator.Send(commandRequest);

            switch (commandResponse.Status)
            {
            case true: return(Ok(commandResponse));

            case false: return(BadRequest(commandResponse));
            }
        }
Ejemplo n.º 2
0
 public async Task RegisterEmployeeAsync(RegisterEmployeeCommandRequest commandRequest)
 {
     await paymentsControlDataContext
     .connection
     .ExecuteAsync("spRegisterEmployee",
                   new
     {
         commandRequest.Id,
         commandRequest.Code,
         commandRequest.FirstName,
         commandRequest.LastName,
         commandRequest.HiringDate
     }, commandType : CommandType.StoredProcedure);
 }
Ejemplo n.º 3
0
        public async Task <HandlerResultEntity <RegisterEmployeeCommandResponse> > Handle(RegisterEmployeeCommandRequest commandRequest, CancellationToken cancellationToken)
        {
            var validationResult = await validator.ValidateAsync(commandRequest, cancellationToken);

            if (validationResult.IsValid)
            {
                switch (await employeeRepository.VerifyEmployeeCodeExistsAsync(commandRequest.Code))
                {
                case true: return(new HandlerResultEntity <RegisterEmployeeCommandResponse>(false, "employee code already exists", null));

                case false:
                {
                    await employeeRepository.RegisterEmployeeAsync(commandRequest);

                    var commandResponse = new RegisterEmployeeCommandResponse(commandRequest.Id);

                    return(new HandlerResultEntity <RegisterEmployeeCommandResponse>(true, string.Empty, commandResponse));
                }
                }
            }
            else
            {
                return(new HandlerResultEntity <RegisterEmployeeCommandResponse>(false, ValidationResultErrorMessage.Format(validationResult), null));
            }
        }