コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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());
        }
コード例 #3
0
 public UpdateAddressCommand(Address4A oldCurrentAddress, Address4A newCurrentAddress)
 {
     OldCurrentAddress = oldCurrentAddress;
     NewCurrentAddress = newCurrentAddress;
 }
コード例 #4
0
 public ChangeCurrentAddressCommand4A(Guid customerId,
                                      Address4A address)
 {
     CustomerId = customerId;
     Address    = address;
 }