public GetCustomerApiResponse2A(Customer2A customer)
 {
     FirstName     = customer.FirstName;
     LastName      = customer.LastName;
     Title         = customer.Title;
     PastAddresses = customer.Addresses
                     .Where(a => !a.CurrentAddress)
                     .Select(a => new AddressResponse2A(a));
     CurrentAddress = new AddressResponse2A(customer.Addresses
                                            .Single(a => a.CurrentAddress));
     DateOfBirth      = customer.DateOfBirth;
     IdDocumentType   = customer.IdDocumentType;
     IdDocumentNumber = customer.IdDocumentNumber;
 }
        public async Task <IActionResult> Post([FromBody] CreateCustomerRequest2A createCustomerRequest)
        {
            // convert request DTO to domain model
            var customer = new Customer2A(createCustomerRequest.FirstName,
                                          createCustomerRequest.LastName,
                                          createCustomerRequest.Title,
                                          createCustomerRequest.DateOfBirth,
                                          createCustomerRequest.IdDocumentType,
                                          createCustomerRequest.IdDocumentNumber,
                                          createCustomerRequest.Addresses.Select(a => new Address2A(a.HouseNoOrName,
                                                                                                    a.Street,
                                                                                                    a.City,
                                                                                                    a.County,
                                                                                                    a.PostCode,
                                                                                                    a.CurrentAddress
                                                                                                    )));

            // command just wrap domain model
            var createCustomerCommand = new CreateCustomerCommand2A(customer);

            // command handler returns response that wraps domain model
            var response = await _mediator.Send(createCustomerCommand);

            if (response.Status == OperationStatus.ValidationFailure)
            {
                return(BadRequest(response.ErrorMessages));
            }

            var customerApiResponse = new CreateCustomerApiResponse2A(response.Value.CustomerId);

            if (response.Status == OperationStatus.Conflict)
            {
                return(Conflict(customerApiResponse));
            }

            return(Ok(customerApiResponse));
        }
 public CreateCustomerCommandResponse3A(Customer2A customer)
 {
     Customer = customer;
 }