diff --git a/src/EllieBot/_common/Abstractions/Extensions/SelfAssignableRolesExtensions.cs b/src/EllieBot/_common/Abstractions/Extensions/SelfAssignableRolesExtensions.cs new file mode 100644 index 0000000..f44488f --- /dev/null +++ b/src/EllieBot/_common/Abstractions/Extensions/SelfAssignableRolesExtensions.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore; +using EllieBot.Db.Models; + +namespace EllieBot.Db; + +public static class SelfAssignableRolesExtensions +{ + public static bool DeleteByGuildAndRoleId(this DbSet roles, ulong guildId, ulong roleId) + { + var role = roles.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId); + + if (role is null) + return false; + + roles.Remove(role); + return true; + } + + public static IReadOnlyCollection GetFromGuild( + this DbSet roles, + ulong guildId) + => roles.AsQueryable().Where(s => s.GuildId == guildId).ToArray(); +} \ No newline at end of file