コード例 #1
0
        public async Task <IHttpActionResult> PostBankAccountBalance(int number, decimal value, string operation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var bankAccount = db.BankAccounts.FirstOrDefault(a => a.Number.Equals(number));

            if (bankAccount == null)
            {
                return(NotFound());
            }

            var bankAccountBalance = new BankAccountBalance();

            bankAccountBalance.id            = Guid.NewGuid();
            bankAccountBalance.BankAccountID = bankAccount.Id;
            bankAccountBalance.Value         = value;
            bankAccountBalance.Operation     = operation.ToLower();
            bankAccountBalance.Creation      = DateTime.Now;

            db.BankAccountBalances.Add(bankAccountBalance);
            var save = await db.SaveChangesAsync();

            var typeOperation = operation.ToLower().Equals("sum") ? "Depósito" : "Saque";

            return(Ok(string.Format("{0} cadastrado com sucesso na conta bancária {1}.", typeOperation, number)));
        }
コード例 #2
0
ファイル: BankAccountService.cs プロジェクト: Shchack/Pocket
        public async Task <BankAccountBalance> GetBankAccountBalanceAsync(Guid userId, Guid assetId)
        {
            AssetBankAccount account = await _bankAccountRepository.GetByAssetIdAsync(userId, assetId);

            if (account == null)
            {
                throw new Exception("Asset bank account not found.");
            }

            BankModel          bank           = _bankService.GetBank(account.BankName);
            TimeSpan           syncSpan       = DateTime.UtcNow - account.LastSyncDateTime.Value;
            BankAccountBalance accountBalance = null;

            if (syncSpan.TotalSeconds > bank.SyncFreqInSeconds)
            {
                IBankIntegrationService bankAccountservice = _bankIntegrationServiceResolver.Resolve(account.BankName);
                var requestParams = new BankAccountsRequestParams(account.Token, account.BankClientId, account.BankAccountId);
                IReadOnlyCollection <ExternalAccountBalanceModel> accountBalances = await bankAccountservice.GetAccountsAsync(requestParams);

                ExternalAccountBalanceModel external = accountBalances.FirstOrDefault(ab => ab.AccountId == account.BankAccountId);
                accountBalance = new BankAccountBalance(external.BankName, external.AccountId, external.Currency, external.Balance);

                await _bankAccountRepository.UpdateLastSyncAsync(userId, assetId, DateTime.UtcNow, accountBalance.AccountName);

                await _unitOfWork.SaveChangesAsync();
            }

            return(accountBalance);
        }
コード例 #3
0
ファイル: BalanceService.cs プロジェクト: Shchack/Pocket
        private async Task <List <BalanceViewModel> > AddBalancesByTemplateAsync(Guid userId, DateTime latestEffectiveDate, DateTime effectiveDate)
        {
            IEnumerable <Balance> latestBalances = await _balanceRepository.GetByEffectiveDateAsync(userId, latestEffectiveDate);

            IList <AssetBankAccount> bankAccounts = await _assetBankAccountRepository.GetByUserIdAsync(userId);

            List <BalanceViewModel> result = new List <BalanceViewModel>();

            foreach (Balance balance in latestBalances)
            {
                decimal value = balance.Value;

                if (bankAccounts.Any(ba => ba.AssetId == balance.AssetId))
                {
                    BankAccountBalance bankAccountBalance = await _bankAccountService.GetBankAccountBalanceAsync(userId, balance.AssetId);

                    if (bankAccountBalance != null)
                    {
                        value = bankAccountBalance.Balance;
                    }
                }

                Balance newBalance = await _balanceRepository.CreateAsync(userId, balance.AssetId, effectiveDate, value);

                var assetModel = new AssetViewModel(balance.Asset);
                var model      = new BalanceViewModel(newBalance, assetModel);
                result.Add(model);
            }

            await _unitOfWork.SaveChangesAsync();

            return(result);
        }
コード例 #4
0
ファイル: BalanceService.cs プロジェクト: Shchack/Pocket
        public async Task <BalanceViewModel> SyncBankAccountBalanceAsync(Guid userId, Guid id)
        {
            BalanceViewModel balanceViewModel;
            Balance          balance = await _balanceRepository.GetByIdAsync(userId, id);

            BankAccountBalance bankAccountBalance = await _bankAccountService.GetBankAccountBalanceAsync(userId, balance.AssetId);

            if (bankAccountBalance != null)
            {
                Balance updatedBalance = await _balanceRepository.UpdateAsync(userId, id, balance.AssetId, bankAccountBalance.Balance);

                balanceViewModel = new BalanceViewModel(updatedBalance);
            }
            else
            {
                balanceViewModel = new BalanceViewModel(balance);
            }

            await _unitOfWork.SaveChangesAsync();

            return(balanceViewModel);
        }
コード例 #5
0
 public void MarkAsModified(BankAccountBalance item)
 {
 }
コード例 #6
0
 public VOBankAccountBalance(BankAccountBalance instance)
 {
     this.instance = instance;
 }