Add pick method

This commit is contained in:
Daniel_I_Am 2020-06-04 02:13:35 +02:00
parent f4cdf5c9c6
commit 09e5b671c8
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
2 changed files with 13 additions and 2 deletions

View File

@ -122,7 +122,7 @@ namespace ChaosBot.Database
string order = null;
if (orderByKey != null)
{
order = $"ORDER BY ${orderByKey}";
order = $"ORDER BY {orderByKey}";
}
string query = $"SELECT {selectColumns} FROM {table} {filter} {order}";

View File

@ -65,6 +65,17 @@ namespace ChaosBot.Database.Repository
}
}
public static Raffle PickRandom()
{
DataTable dataTable = Controller.SelectQuery(Table, "*", orderByKey: "RANDOM()");
if (dataTable.Rows.Count == 0) return null;
DataRow row = dataTable.Rows[0];
int idFetch = Convert.ToInt32((long)row["id"]);
string userIdFetch = row["userId"].ToString();
return new Raffle(idFetch, userIdFetch);
}
// public static void delete()
// {
//