Ejemplo n.º 1
0
        public async Task <bool> UserHasRole(ulong userId, BotRoleType roleType)
        {
            var role = await _dbContext.BotUserRoles
                       .SingleOrDefaultAsync(r => r.UserId == userId && r.BotRoleType == roleType);

            return(role != null);
        }
Ejemplo n.º 2
0
        public async Task AddUserRole(ulong userId, BotRoleType roleType)
        {
            var botUserRole = new BotUserRole()
            {
                UserId      = userId,
                BotRoleType = roleType
            };

            await _dbContext.AddAsync(botUserRole);

            await _dbContext.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task RemoveUserRole(ulong userId, BotRoleType roleType)
        {
            var role = await _dbContext.BotUserRoles
                       .SingleOrDefaultAsync(r => r.UserId == userId && r.BotRoleType == roleType);

            if (role == null)
            {
                throw new Exception("User does not have role");
            }

            _dbContext.Remove(role);

            await _dbContext.SaveChangesAsync();
        }