public async Task <Customer4A4> Get(Guid customerId) { using (var conn = new SqlConnection()) { var customerData = await conn.QuerySingleOrDefaultAsync <CustomerData4A>( "SELECT * FROM Customers WHERE CustomerId = @customerId", new { customerId }); var addressesData = await conn.QueryAsync <AddressData4A>( "SELECT * FROM Addresses WHERE Customer", new { customerId }); var nameResult = CustomerName.Create(customerData.Title, customerData.FirstName, customerData.LastName); var dobResult = Dob.Create(customerData.DateOfBirth); var idDocumentResult = IdDocument.Create(customerData.IdDocumentType, customerData.IdDocumentNumber); var addresses = addressesData.Select(a => Address4A.Create(a.AddressId, a.HouseNoOrName, a.Street, a.City, a.County, a.PostCode, a.CurrentAddress).Value); return(new Customer4A4(customerData.CustomerId, nameResult.Value, dobResult.Value, idDocumentResult.Value, addresses)); } }
public async Task <IActionResult> Put([FromRoute] Guid customerId, [FromBody] AddressRequest4A request) { // value objects validate their inputs var addressResult = Address4A.Create(Guid.NewGuid(), request.HouseNoOrName, request.Street, request.City, request.County, request.PostCode, true); if (addressResult.Status == OperationStatus.ValidationFailure) { return(BadRequest(addressResult.ErrorMessages)); } // command handler owns the business logic that updates the customer's current address var response = await _mediator.Send(new ChangeCurrentAddressCommand4A(customerId, addressResult.Value)); if (response.Status == OperationStatus.NotFound) { return(NotFound(customerId)); } return(NoContent()); }
public UpdateAddressCommand(Address4A oldCurrentAddress, Address4A newCurrentAddress) { OldCurrentAddress = oldCurrentAddress; NewCurrentAddress = newCurrentAddress; }
public ChangeCurrentAddressCommand4A(Guid customerId, Address4A address) { CustomerId = customerId; Address = address; }