/// <summary> /// this function will retrieve the last used bank account for the given user /// </summary> /// <param name="user">the last used bank Account</param> /// <returns>the last used Bank Account</returns> public BankAccount GetLastUsedBank(Login.UserControllers.User user) { List <BankAccount> bankAccounts = (from cbf in base.ConturiBancareFurnizori join ulu in UtilizatoriLastUsed on cbf.Id equals ulu.ConturiBancareLastUsed where ulu.UtilizatorId == user.ID && (ulu.Activ ?? false) select new BankAccount { ID = cbf.Id, Bank = cbf.Banca, Account = cbf.Cont }).ToList(); return(bankAccounts.FirstOrDefault()); }
/// <summary> /// this function will retrieve the last used bank account for the given user /// </summary> /// <param name="user">the last used bank Account</param> /// <returns>the last used Bank Account</returns> public static BankAccount GetLastUsedBank(Login.UserControllers.User user) { //we generate the select command for the query String QueryCommand = "SELECT * " + "FROM seller.conturi_bancare_furnizori AS cbf " + "LEFT JOIN seller.utilizatori_last_used AS ulu " + "ON ulu.conturi_bancare_last_used == cbf.id " + "WHERE ulu.utilizator_id = :p_user_id AND ulu.activ"; //and set the query parameters NpgsqlParameter QueryParameter = new NpgsqlParameter(":p_user_id", user.ID); //we attempt to open the connection if (!PgSqlConnection.OpenConnection()) { return(null); } //if we manage we return the results to a dataTable DataTable result = PgSqlConnection.ExecuteReaderToDataTable(QueryCommand, QueryParameter); //we check if the result is empty or not if (result != null && result.Rows.Count > 0) { //if not we convert the result to my object list return(result.AsEnumerable().Select(row => new BankAccount { ID = row.Field <Int32>("ID"), Bank = row.Field <String>("BANCA"), Account = row.Field <String>("CONT") }).First()); } //else we return the null object else { return(null); } }