コード例 #1
0
        public ActionResult Index()
        {
            /// Aici se ia lista de MyAccounts
            using (CryptoWalletDbContext ctx = new CryptoWalletDbContext())
            {
                /// gasesc user-ul conectat si ii caut conturile bancare
                ExchangeService              echangeService = new ExchangeService();
                List <CurrencyRate>          rates          = echangeService.GetConversionRate(Currency.EUR, new Currency[] { Currency.EUR, Currency.BTC, Currency.GBP, Currency.USD, Currency.XRP });
                List <CurrencyRateViewModel> ratesViewModel = rates.Select(a => new CurrencyRateViewModel
                {
                    Currency = a.Currency.ToString(),
                    Rate     = a.Rate
                }).ToList();
                User user = ctx.Users.AsNoTracking().FirstOrDefault(u => u.Email == User.Identity.Name);
                List <UserBankAccount>      userBankAccounts         = ctx.UserBankAccounts.Where(u => u.User.UserId == user.UserId).ToList();
                List <BankAccountViewModel> myBankAccountsViewModels = userBankAccounts.Select(a => new BankAccountViewModel
                {
                    AccountId = a.AccountId,
                    Amount    = a.Amount,
                    Currency  = a.Currency,
                }).ToList();


                foreach (var item in myBankAccountsViewModels)
                {
                    item.CurrencyRate = ratesViewModel.FirstOrDefault(s => s.Currency == item.Currency).Rate;
                }
                BankAccountViewModelTest ViewModel = new BankAccountViewModelTest();
                ViewModel.Lista = myBankAccountsViewModels;
                SetupIndexDeposits(ViewModel, user);
                return(View(ViewModel));
            }
        }
コード例 #2
0
        private void SetupIndexDeposits(BankAccountViewModelTest viewModel, User user)
        {
            using (CryptoWalletDbContext ctx = new CryptoWalletDbContext())
            {
                UserBankAccount bankAccount = ctx.UserBankAccounts.FirstOrDefault(x => x.UserId == user.UserId && x.Currency == "EUR");

                if (bankAccount != null)
                {
                    List <UserTransaction> transactions = ctx.UserTransactions.Where(x => x.FromAccountId == bankAccount.AccountId && x.ToAccountId == bankAccount.AccountId).ToList();
                    if (transactions != null)
                    {
                        foreach (var transaction in transactions)
                        {
                            viewModel.sumDeposits += transaction.Amount;
                        }
                    }
                }
            }
        }