diff --git a/ChaosBot/Database/Repository/RaffleRepository.cs b/ChaosBot/Database/Repository/RaffleRepository.cs index a3df9cd..f5c1970 100644 --- a/ChaosBot/Database/Repository/RaffleRepository.cs +++ b/ChaosBot/Database/Repository/RaffleRepository.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Data; +using System.Linq; using ChaosBot.Database.Entity; namespace ChaosBot.Database.Repository @@ -8,10 +10,40 @@ namespace ChaosBot.Database.Repository { private static readonly string Table = "RaffleTable"; - // public static Raffle[] all() - // { - // - // } + public static Raffle[] all() + { + DataTable dataTable = Controller.SelectQuery(Table); + + List raffles = new List(); + foreach (DataRow row in dataTable.Rows) + { + int id = Convert.ToInt32((long) row["id"]); + string userId = row["userId"].ToString(); + + raffles.Add(new Raffle(id, userId)); + } + + return raffles.ToArray(); + } + + public static Raffle[] selectUser(string userId) + { + Dictionary filterDict = new Dictionary(); + filterDict.Add("userId", userId); + + DataTable dataTable = Controller.SelectQuery(Table, filterColumns: filterDict); + + List raffles = new List(); + foreach (DataRow row in dataTable.Rows) + { + int id = Convert.ToInt32((long) row["id"]); + string userIdFetch = row["userId"].ToString(); + + raffles.Add(new Raffle(id, userIdFetch)); + } + + return raffles.ToArray(); + } public static void insert(Raffle raffle) {