public async Task <OperationResult <UpdateCustomerResponse> > UpdateCustomerAsync(UpdateCustomerRequest request) { _logger.LogInformation($"Calling {nameof(UpdateCustomerAsync)}"); var isValid = request.Validate(); if (!isValid) { _logger.LogError("Error: Invalid request, cannot update customer"); return(OperationResult <UpdateCustomerResponse> .Failure("Invalid request, cannot update customer")); } var operationResult = await _customerRepository.UpdateCustomerAsync(new Customer { Id = request.Id, Name = request.Name, Address = request.Address }).ConfigureAwait(false); if (operationResult.Status) { _logger.LogInformation("Customer updated successfully"); var updatedCustomer = operationResult.Data; return(OperationResult <UpdateCustomerResponse> .Success(new UpdateCustomerResponse(new CustomerDisplayModel(updatedCustomer.Name, updatedCustomer.Address)))); } _logger.LogError("Error: Cannot update customer"); return(OperationResult <UpdateCustomerResponse> .Failure("Cannot update customer")); }
public async Task <OperationResult <UpdateCustomerResponse> > UpdateCustomerAsync(UpdateCustomerRequest request) { var isValid = request.Validate(); if (!isValid) { _logger.LogError($"Error. Invalid request: {JsonConvert.SerializeObject(request)}"); return(OperationResult <UpdateCustomerResponse> .Failure("Invalid request")); } var operationResult = await _customerRepository.UpdateCustomerAsync(request.Customer.ToDataAccess()).ConfigureAwait(false); if (!operationResult.Status) { _logger.LogError($"Error: {operationResult.Message}"); return(OperationResult <UpdateCustomerResponse> .Failure("Cannot create customer, error occured")); } var displayCustomer = operationResult.Data.ToDisplay(); return(OperationResult <UpdateCustomerResponse> .Success(new UpdateCustomerResponse(displayCustomer))); }