public double GetUserFiatBalance(int id) { using (var dbContext = new CryptocurrencyExchangeDbContext()) { return(dbContext.TransactionsDbSet.Where(u => u.UserId == id).ToList().Sum(x => x.Fiat)); } }
public List <User> GetExistingUsers() { using (var dbContext = new CryptocurrencyExchangeDbContext()) { return(dbContext.UsersDbSet.ToList()); } }
public void AddUser(User newUser) { using (var dbContext = new CryptocurrencyExchangeDbContext()) { dbContext.UsersDbSet.Add(newUser); dbContext.SaveChanges(); } }
public void RegisterTransaction(Transaction transaction) { using (var dbContext = new CryptocurrencyExchangeDbContext()) { var sqlTransaction = _mapper.Map <Transaction, SqlTransaction>(transaction); dbContext.TransactionsDbSet.Add(sqlTransaction); dbContext.SaveChanges(); } }
public User GetUserByLogin(string login) { User user = null; using (var dbContext = new CryptocurrencyExchangeDbContext()) { return(dbContext.UsersDbSet.SingleOrDefault(u => u.Login == login)); } return(user); }
public IEnumerable <Transaction> GetTransactionsHistory(int activeUserId) { List <Transaction> mappedTransactions = new List <Transaction>(); using (var dbContext = new CryptocurrencyExchangeDbContext()) { var transactionsFromSql = dbContext.TransactionsDbSet.Where(t => t.UserId == activeUserId).OrderBy(d => d.TransactionDate).ToList(); foreach (var transaction in transactionsFromSql) { mappedTransactions.Add(_mapper.Map <SqlTransaction, Transaction>(transaction)); } return(mappedTransactions); } }
public User GetUser(string userLogin, string userPassword) { User loggedInUser; using (var dbContext = new CryptocurrencyExchangeDbContext()) { loggedInUser = dbContext.UsersDbSet.SingleOrDefault(user => user.Login == userLogin); if (loggedInUser != null && loggedInUser.Password != userPassword) { return(null); } } return(loggedInUser); }
public bool CheckUserPassword(User user) { var passwordCheck = true; using (var dbContext = new CryptocurrencyExchangeDbContext()) { var foundUser = dbContext.UsersDbSet.SingleOrDefault(u => u.Login == user.Login); if (foundUser == null || foundUser.Password != user.Password) { passwordCheck = false; } return(passwordCheck); } }
public double GetUserCryptocurrencyBalance(string currencyName, int userId) { using (var dbContext = new CryptocurrencyExchangeDbContext()) { var choosenCurrencyTransactionList = dbContext.TransactionsDbSet.Where(c => c.CurrencyName == currencyName && c.UserId == userId).ToList(); if (choosenCurrencyTransactionList.Count > 0) { return(Math.Round(choosenCurrencyTransactionList.Sum(x => x.Amount), 7)); } else { return(0); } } }
public void RegisterWebTransaction(Transaction transactionEntity) { using (var dbContext = new CryptocurrencyExchangeDbContext()) { } }