public async Task <IActionResult> Delete(int id) { ActionResult result; var input = new DeleteCustomerInput(); DeleteCustomerOutput output; try { input.CustomerId = id; output = await this._facadeOrchestratorCustomer.DeleteCustomerAsync(input); if (output.Success) { result = Ok(output.Success); } else { result = BadRequest(output.GetJoinedErrors()); } } catch (Exception ex) { result = BadRequest(ex); } return(result); }
public async Task <OperationResult> DeleteCustomerAsync(DeleteCustomerInput input) { var validationResult = await _customerValidator.ValidateDeleteCustomer(input); if (validationResult.IsSuccess) { var entity = await _customerRepository.GetCustomer(input.Email); await _customerRepository.RemoveAsync(entity); return(OperationResult.Success()); } return(OperationResult <CustomerDto> .Fail(validationResult)); }
public async Task <ValidationResult> ValidateDeleteCustomer(DeleteCustomerInput input) { ValidationResult validationResult = new(); if (string.IsNullOrWhiteSpace(input.Email)) { validationResult.Messages.Add(new(nameof(DeleteCustomerInput.Email), "Debe ingresar un email.")); } else if (!input.Email.IsEmail()) { validationResult.Messages.Add(new(nameof(CreateCustomerInput.Email), "Debe ingresar un email valido.")); } else { Customer customer = await _customerRepository.GetCustomer(input.Email); if (customer is null) { validationResult.Messages.Add(new(nameof(DeleteCustomerInput.Email), "no existe un cliente con este email.")); } } return(validationResult); }
public async Task <DeleteCustomerOutput> DeleteCustomerAsync(DeleteCustomerInput input) { DeleteCustomerOutput output = await Orchestrator.Execute <DeleteCustomer, DeleteCustomerInput, DeleteCustomerOutput, DeleteCustomerValidator>(_customerManager, input); return(output); }