Add count function to rafflerepository

This commit is contained in:
Daniel_I_Am 2020-06-04 02:21:25 +02:00
parent 0a6dab9cf5
commit fcd3c04ebb
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
2 changed files with 20 additions and 3 deletions

View File

@ -24,6 +24,23 @@ namespace ChaosBot.Database.Repository
}
return raffles.ToArray();
}
public static int count()
{
DataTable dataTable = Controller.SelectQuery(Table, "COUNT(*)");
return Convert.ToInt32(dataTable.Rows[0]["COUNT(*)"]);
}
public static int count(string userId)
{
Dictionary<string, object> filterDict = new Dictionary<string, object>();
filterDict.Add("userId", userId);
DataTable dataTable = Controller.SelectQuery(Table, "COUNT(*)", filterDict);
return Convert.ToInt32(dataTable.Rows[0]["COUNT(*)"]);
}
public static Raffle[] selectUser(string userId)

View File

@ -156,7 +156,7 @@ namespace ChaosBot.Discord.Modules
sb.AppendLine($"{Context.User.Mention} has added {amount} rafflepoints to <@{userId}>.");
sb.AppendLine();
sb.AppendLine($"<@{userId}> now has {RaffleRepository.selectUser(userId.ToString()).Length} rafflepoints!");
sb.AppendLine($"<@{userId}> now has {RaffleRepository.count(userId.ToString())} rafflepoints!");
}
private void PickRaffle(StringBuilder sb)
@ -178,8 +178,8 @@ namespace ChaosBot.Discord.Modules
{
ulong userId = Convert.ToUInt64(user.Substring(3, user.Length-4));
sb.AppendLine($"<@{userId}>, you have {RaffleRepository.selectUser(userId.ToString()).Length} rafflepoints.");
sb.AppendLine($"There is a total of {RaffleRepository.all().Length} rafflepoints.");
sb.AppendLine($"<@{userId}>, you have {RaffleRepository.count(userId.ToString())} rafflepoints.");
sb.AppendLine($"There is a total of {RaffleRepository.count()} rafflepoints.");
}
}
}