示例#1
0
        public async ValueTask <IActionResult> GetCustomers([FromBody] GetCustomerByCPFCommandInput command, [FromServices] CustomerHandler handler)
        {
            try
            {
                var result = await handler.Handle(command);

                return(GetResult(result));
            }
            catch (Exception exception)
            {
                _logger.LogError("An exception has occurred at {dateTime}. " +
                                 "Exception message: {message}." +
                                 "Exception Trace: {trace}", DateTime.UtcNow, exception.Message, exception.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
示例#2
0
        public async ValueTask <GetCustomerByCPFCommandResult> Handle(GetCustomerByCPFCommandInput command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GetCustomerByCPFCommandResult(false, "Incorrect  data!", null, StatusCodes.Status400BadRequest, command.Notifications));
            }

            CustomersJson customerRepository = await _customerJsonRepository.GetCustomerByCpf(command);

            if (customerRepository == null)
            {
                return(new GetCustomerByCPFCommandResult(false, "NotFound", null, StatusCodes.Status404NotFound, command.Notifications));
            }

            Customer customer = new Customer(customerRepository.Id, customerRepository.Name, customerRepository.Cpf, customerRepository.Salary);

            customer.SalaryCustomerCalculation();

            GetCustomerByCPFCommandOutput customerByCPFcommandOutput = new GetCustomerByCPFCommandOutput(customer.Id, customer.Name, customer.Cpf, customer.Salary);

            return(new GetCustomerByCPFCommandResult(true, "Success!", customerByCPFcommandOutput, StatusCodes.Status200OK, command.Notifications));
        }
 public async ValueTask <CustomersJson> GetCustomerByCpf(GetCustomerByCPFCommandInput command)
 {
     return(await Task.FromResult(_listClientesJson.Where(x => x.Cpf == command.CPF).FirstOrDefault()));
 }
        public async ValueTask <Customer> GetCustomerByCpf(GetCustomerByCPFCommandInput command)
        {
            var customers = JsonConvert.DeserializeObject <CustomerQuery>(CustomerResource.Customers);

            return(await Task.FromResult(customers.Clientes.Where(x => x.Cpf == command.CPF).FirstOrDefault()));
        }