示例#1
0
        public async Task <Domain.Entities.Transaction> Withdraw(decimal amount)
        {
            ValidationTransaction.ValidateAmount(amount);
            var user = await _userService.FindFirstAsync(u => u.Id == _userId);

            ValidationTransaction.ValidateAmountBank(amount, user);

            var withdraw = _transactionService.Withdraw(amount, _userId);

            user.AmountBank   -= amount;
            user.AmountWallet += amount;

            _userService.Update(user);

            await SaveAsync();

            return(withdraw);
        }
示例#2
0
        public async Task <Domain.Entities.Transaction> Deposit(decimal amount)
        {
            ValidationTransaction.ValidateAmount(amount);
            var user = await _userService.FindFirstAsync(u => u.Id == _userId);

            ValidationTransaction.ValidateAmountWallet(amount, user);

            var deposit = _transactionService.Deposit(amount, _userId);

            user.AmountBank   += amount;
            user.AmountWallet -= amount;

            _userService.Update(user);

            await SaveAsync();

            return(deposit);
        }
示例#3
0
        public async Task <Domain.Entities.Transaction> Transfer(decimal amount, int userIdDestiny)
        {
            ValidationTransaction.ValidateAmount(amount);
            ValidationTransaction.ValidateUserTransfer(_userId, userIdDestiny);
            var userDestiny = await _userService.FindFirstAsync(u => u.Id == userIdDestiny);

            ValidationTransaction.ValidatePassport(userDestiny);
            var user = await _userService.FindFirstAsync(u => u.Id == _userId);

            ValidationTransaction.ValidateAmountBank(amount, user);

            var transfer = _transactionService.Transfer(amount, _userId, userIdDestiny);

            user.AmountBank        -= amount;
            userDestiny.AmountBank += amount;

            _userService.Update(user);
            _userService.Update(userDestiny);

            await SaveAsync();

            return(transfer);
        }