private decimal TotalAmount() { using (CryptoWalletDBContext ctx = new CryptoWalletDBContext()) { User currentUser = ctx.Users.AsNoTracking().FirstOrDefault(u => u.Email == User.Identity.Name); List <CurrencyRate> rates = new ExchangeService().GetConversionRate(Currency.EUR, new Currency[] { Currency.USD, Currency.GBP, Currency.BTC, Currency.XRP }); decimal totalAmount = ctx.UsersBankAccounts.FirstOrDefault(u => u.Currency == "EUR" && u.UserId == currentUser.UserId).Amount; UserBankAccount userBankAccount = ctx.UsersBankAccounts.FirstOrDefault(u => u.Currency == "USD" && u.UserId == currentUser.UserId); if (userBankAccount != null) { rates = new ExchangeService().GetConversionRate(Currency.USD, new Currency[] { Currency.EUR }); totalAmount += (userBankAccount.Amount * rates.First().Rate); } userBankAccount = ctx.UsersBankAccounts.FirstOrDefault(u => u.Currency == "GBP" && u.UserId == currentUser.UserId); if (userBankAccount != null) { rates = new ExchangeService().GetConversionRate(Currency.GBP, new Currency[] { Currency.EUR }); totalAmount += (userBankAccount.Amount * rates.First().Rate); } userBankAccount = ctx.UsersBankAccounts.FirstOrDefault(u => u.Currency == "BTC" && u.UserId == currentUser.UserId); if (userBankAccount != null) { rates = new ExchangeService().GetConversionRate(Currency.BTC, new Currency[] { Currency.EUR }); totalAmount += (userBankAccount.Amount * rates.First().Rate); } userBankAccount = ctx.UsersBankAccounts.FirstOrDefault(u => u.Currency == "XRP" && u.UserId == currentUser.UserId); if (userBankAccount != null) { rates = new ExchangeService().GetConversionRate(Currency.XRP, new Currency[] { Currency.EUR }); totalAmount += (userBankAccount.Amount * rates.First().Rate); } return(totalAmount); } }