Пример #1
0
        public async Task <Account> Handle(CloseAccountCommand request, CancellationToken cancellationToken)
        {
            var account = await _table.GetAsync(request.AccountId, request.UserId);

            if (account == null)
            {
                throw new ApplicationApiException(HttpStatusCode.BadRequest, "Account not found");
            }

            account.IsDeleted    = true;
            account.LastModified = DateTime.UtcNow;

            return(await _table.UpdateAsync(account));
        }
        public async Task <Unit> Handle(TransferCommand request, CancellationToken cancellationToken)
        {
            var transaction = await _transactionsTable.GetByIdAsync(request.TransactionId);

            var writeOffAccount = await _accountsTable.GetAsync(transaction.WriteOffAccount, transaction.UserId);

            ValidateWriteOffAccount(writeOffAccount, transaction);

            var destinationAccount = await _accountsTable.GetByIdAsync(transaction.DestinationAccount);

            ValidateDestinationAccount(destinationAccount, transaction);

            writeOffAccount.Balance     -= transaction.Amount;
            writeOffAccount.LastModified = DateTime.UtcNow;

            destinationAccount.Balance     += transaction.Amount;
            destinationAccount.LastModified = DateTime.UtcNow;

            await _accountsTable.UpdateAsync(writeOffAccount);

            await _accountsTable.UpdateAsync(destinationAccount);

            return(Unit.Value);
        }
Пример #3
0
        public async Task <Unit> Handle(RefillCommand request, CancellationToken cancellationToken)
        {
            var account = await _table.GetAsync(request.AccountId, request.UserId);

            if (account == null)
            {
                throw new ApplicationApiException(HttpStatusCode.BadRequest, "Account not found");
            }

            account.Balance     += request.Amount;
            account.LastModified = DateTime.UtcNow;

            await _table.UpdateAsync(account);

            return(Unit.Value);
        }
        public async Task <Account> Handle(EditAccountCommand request, CancellationToken cancellationToken)
        {
            var account = await _accountsTable.GetAsync(request.AccountId, request.UserId);

            if (account == null)
            {
                throw new ApplicationApiException(HttpStatusCode.BadRequest, "Account not found");
            }

            request.Adapt(account.AccountDetail);

            account.LastModified = DateTime.UtcNow;
            account.AccountDetail.LastModified = account.LastModified;

            return(await _accountsTable.UpdateAsync(account));
        }