add put vor customer

This commit is contained in:
Lars Unruh
2023-06-08 12:36:57 +02:00
parent c805ce20a8
commit 7b1aaacfb5
6 changed files with 74 additions and 11 deletions

View File

@@ -82,6 +82,29 @@ public class CustomerService : ICustomerService
return customerDto;
}
public async Task<CustomerDto> UpdateAsync(Guid customerId, CustomerForUpdateDto customerForUpdate, CancellationToken cancellationToken)
{
var customer = await _customerRepository.GetByIdAsync(customerId, cancellationToken);
if (customer is null)
{
throw new BusinessPartnerNotFoundException(customerId);
}
SetIfContains(customerForUpdate.Salutaion, customer, nameof(customer.Salutation));
SetIfContains(customerForUpdate.Name1, customer, nameof(customer.Name1));
SetIfContains(customerForUpdate.Name2, customer, nameof(customer.Name2));
SetIfContains(customerForUpdate.Email, customer, nameof(customer.Email));
SetIfContains(customerForUpdate.Iban, customer, nameof(customer.Iban));
SetIfContains(customerForUpdate.PhoneNumber, customer, nameof(customer.PhoneNumber));
await _unitOfWork.SaveChangesAsync(cancellationToken);
var customerDto = ConvertToCustomerDto(customer);
return customerDto;
}
private static CustomerDto ConvertToCustomerDto(Customer customer)
{
var customerDto = new CustomerDto
@@ -96,4 +119,14 @@ public class CustomerService : ICustomerService
};
return customerDto;
}
public static void SetIfContains<T>(T value, Customer customer, string propertyName)
{
if (value is not null)
{
customer.GetType().GetProperty(propertyName).SetValue(customer, value);
}
}
}