예제 #1
0
        public async Task <IActionResult> Post([FromBody] AccountDTO accountDto, CancellationToken ct)
        {
            var addNewAccountCommand = new AddNewAccountCommand(
                new Name {
                FirstName = accountDto.Name.FirstName, LastName = accountDto.Name.LastName
            },
                accountDto.Addresses.Select(addr =>
                                            new Address(
                                                addr.FistLineOfAddress,
                                                Enum.Parse <AddressType>(addr.AddressType),
                                                addr.State,
                                                addr.ZipCode))
                .ToList(),
                new ContactDetails {
                Email = accountDto.ContactDetails.Email, TelephoneNumber = accountDto.ContactDetails.TelephoneNumber
            },
                new CardDetails {
                CardNumber = accountDto.CardDetails.CardNumber, CardSecurityCode = accountDto.CardDetails.CardSecurityCode
            }
                );

            await _commandProcessor.SendAsync(addNewAccountCommand, false, ct);

            var account = await _queryProcessor.ExecuteAsync(new GetAccountById(addNewAccountCommand.Id), ct);

            return(Ok(AccountDTO.FromQueryResult(account)));
        }
예제 #2
0
        public async Task <IActionResult> Get(string id, CancellationToken ct)
        {
            var accountById = new GetAccountById(Guid.Parse(id));
            var account     = await _queryProcessor.ExecuteAsync(accountById, ct);

            return(Ok(AccountDTO.FromQueryResult(account)));
        }