예제 #1
0
        public async Task <IDatabaseUser> RetrieveUserFromTableAsync(Enums.DatabaseTables table, string userId)
        {
            if (userId == null)
            {
                return(null);
            }
            if (RetrieveConnection.State != ConnectionState.Open)
            {
                RetrieveConnection.Open();
            }
            var retrievingTable = table.ToString();

            Log.Debug("Retrieving {userId} from table {table}", userId, retrievingTable);
            //TODO: add QueryFirstOrDefault after you know what default returns
            var output = (await RetrieveConnection.QueryAsync <DatabaseUser>(
                              $"SELECT * FROM {retrievingTable} WHERE UserID = @UserId ",
                              new { RetrievingTable = retrievingTable, UserId = userId }).ConfigureAwait(false)).ToList();

            if (output.Any())
            {
                return(output.First());
            }
            Log.Warning("{userId} not in table {table}", userId, retrievingTable);
            return(null);
        }
예제 #2
0
        public async Task <List <IDatabaseUser> > RetrieveNumberOfUsersFromTableAsync
            (Enums.DatabaseTables table, int limit,
            Enums.DatabaseUserPointsOrderRow orderRow = Enums.DatabaseUserPointsOrderRow.None)
        {
            if (RetrieveConnection.State != ConnectionState.Open)
            {
                RetrieveConnection.Open();
            }
            var retrievingTable = table.ToString();

            Log.Debug("Retrieving all users from table {table}", retrievingTable);
            var orderString = "";

            if (orderRow != Enums.DatabaseUserPointsOrderRow.None)
            {
                orderString = $"ORDER BY {orderRow.ToString()}";
            }
            if (table != Enums.DatabaseTables.UserPoints && orderRow != Enums.DatabaseUserPointsOrderRow.None)
            {
                throw new Exception("Bad parameter. When using other than UserPoints table orderRow needs to be None.");
            }
            var output =
                (await RetrieveConnection.QueryAsync <DatabaseUser>(
                     $"SELECT * FROM {retrievingTable} {orderString} DESC LIMIT {limit}",
                     new DynamicParameters()).ConfigureAwait(false)).ToList();
            var results = output.ToList <IDatabaseUser>();

            if (output.Any())
            {
                return(results);
            }
            Log.Warning("{table} table is empty!", retrievingTable);
            return(null);
        }
예제 #3
0
        public async Task <List <IDatabaseUser> > RetrieveAllUsersFromTableAsync(Enums.DatabaseTables table)
        {
            if (RetrieveConnection.State != ConnectionState.Open)
            {
                RetrieveConnection.Open();
            }
            var retrievingTable = table.ToString();

            Log.Debug("Retrieving all users from table {table}", retrievingTable);
            var output =
                (await RetrieveConnection.QueryAsync <DatabaseUser>($"SELECT * FROM {retrievingTable}",
                                                                    new DynamicParameters()).ConfigureAwait(false)).ToList();
            var results = output.ToList <IDatabaseUser>();

            if (output.Any())
            {
                return(results);
            }
            Log.Warning("{table} table is empty!", retrievingTable);
            return(null);
        }