private async Task <Result <Guid> > CreateWalletAsync(Guid userId, string name, WalletKind kind, CancellationToken token)
        {
            var user = await _context.Users.SingleAsync(e => e.Id == userId, token);

            using (var transaction = await _context.BeginTransactionAsync(token))
            {
                var wallet = new Domain.Wallet(Guid.NewGuid(), name, kind, user);
                await _context.AddAsync(wallet, token);

                await _context.SaveChangesAsync(token);

                var result = await _pspService.CreateWalletAsync(wallet, token);

                if (!result.Succeeded)
                {
                    await transaction.RollbackAsync(token);

                    return(Failure <Guid>(result));
                }

                wallet.SetIdentifier(result.Data);

                await _context.SaveChangesAsync(token);

                await transaction.CommitAsync(token);

                return(Success(wallet.Id));
            }
        }
Example #2
0
        public async Task HandleAsync(CreateWalletCommand command)
        {
            var investor = await _eventRepository.GetByIdAsync <Investor>(command.InvestorId);

            if (investor == null)
            {
                throw new StocqresException("Investor not exist");
            }

            var wallet = new Domain.Wallet(command.InvestorId, Currency.PLN, command.Amount);
            await _eventRepository.SaveAsync(wallet);
        }