示例#1
0
        public async Task <ActionResult <Guid> > ChangeCurrentAddress([FromRoute] Guid customerId,
                                                                      [FromBody] AddressRequest4I request)
        {
            // value objects validate their inputs
            var addressResult = Address4I.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 ChangeCurrentAddressCommand4I(customerId,
                                                                                  addressResult.Value));

            if (response.Status == OperationStatus.NotFound)
            {
                return(NotFound(customerId));
            }

            return(NoContent());
        }
 public ChangeCurrentAddressCommand4I(Guid customerId,
                                      Address4I address)
 {
     CustomerId = customerId;
     Address    = address;
 }