Example #1
0
        public async Task <AccountLaunch> LaunchDispenseAccountAsync(AccountLaunch accountLaunch)
        {
            var accountCredit = await GetAccountAsync(accountLaunch.AccountCredit);

            var accountDebit = await GetAccountAsync(accountLaunch.AccountDebit);

            if (accountDebit == null)
            {
                return new AccountLaunch {
                           Message = messages.ACCOUNT_DEBIT_NOT_EXISTS(), State = false
                }
            }
            ;


            if (accountLaunch.Value > accountDebit.CreditInCash)
            {
                return new AccountLaunch {
                           Message = messages.ACCOUNT_FOUNDS_INSUFFICIENT(), State = false
                }
            }
            ;

            if (accountCredit == null)
            {
                return new AccountLaunch {
                           Message = messages.ACCOUNT_NOT_FOUND(), State = false
                }
            }
            ;

            var list = new List <AccountLaunch>
            {
                new AccountLaunch
                {
                    AccountCredit = accountCredit.Account,
                    Value         = (accountCredit.CreditInCash + accountLaunch.Value),
                    State         = true,
                    Debit         = false
                },
                new AccountLaunch
                {
                    AccountDebit = accountDebit.Account,
                    Value        = (accountDebit.CreditInCash - accountLaunch.Value),
                    State        = true,
                    Debit        = true
                }
            };

            await UpdateAccountsAsync(list);

            logsService.SaveLog(list);

            return(new AccountLaunch {
                Message = messages.DEBIT_MADE_SUCCESS(), State = true
            });
        }

        #endregion
    }
}