Rework DeletePoints method to use Count Repository method

This commit is contained in:
Daniel_I_Am 2020-06-06 02:42:14 +02:00
parent 343e0e7626
commit 9871d402de
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -102,18 +102,22 @@ namespace ChaosBot.Discord.Modules
{ "userId", userId }, { "userId", userId },
{ "guildId", Context.Guild.Id } { "guildId", Context.Guild.Id }
}; };
Dictionary<string, object> selectfilterDict = new Dictionary<string, object>();
selectfilterDict.Add("userId", userId); int matches = PointsRepository.Count(userId.ToString(), Context.Guild.Id.ToString());
selectfilterDict.Add("guildId", Context.Guild.Id);
DataTable dt = Controller.SelectQuery(Table, "COUNT(*)", selectfilterDict);
int matches = dt.Rows[0]["COUNT(*)"];
if (matches > 0) if (matches > 0)
{ {
Controller.DeleteQuery("PointsTable", filterColumns); Controller.DeleteQuery("PointsTable", filterColumns);
await ReplyAsync($"{Context.User.Mention} has removed <@{userId}> from the database.", false);
} string message = $"{Context.User.Mention} has removed <@{userId}> from the database.";
await ReplyAsync(message, false);
_logger.Info($"PointsCommands.DeletePoints: {message}");
}
else else
await ReplyAsync($"{Context.User.Mention} has failed to remove <@{userId}> from the database, <@{userId}> does not exist. ", false); {
string message = $"{Context.User.Mention} has failed to remove <@{userId}> from the database, <@{userId}> does not exist.";
await ReplyAsync(message, false);
_logger.Warn($"PointsCommands.DeletePoints: {message}");
}
} }
} }
} }