public async Task GetCommand(CommandContext ctx, [RemainingText] string name) { using (var db = new RolesContext()) { var role = db.AssignableRoles .Where(r => r.ServerId == ctx.Guild.Id.ToString()) .Single(r => r.Name == name); if (role == null) { await ctx.RespondAsync("I couldn't find a role in this server by that name."); return; } try { DiscordRole dRole = ctx.Guild.Roles.Single(r => r.Value.Id.ToString() == role.RoleId).Value; await ctx.Member.GrantRoleAsync(dRole, "[Kasumi] Giving user self-assignable role."); await ctx.RespondAsync($"Gave you the `{dRole.Name}` role."); } catch { await ctx.RespondAsync( "An error occurred when trying to give you a role. The role you want has probably been deleted."); } } }
public async Task RemoveCommand(CommandContext ctx, [RemainingText] string name) { using (var db = new RolesContext()) { var role = db.AssignableRoles .Where(r => r.ServerId == ctx.Guild.Id.ToString()) .Single(r => r.Name == name); if (role == null) { await ctx.RespondAsync("I couldn't find a role in this server by that name."); return; } DiscordRole dRole = ctx.Guild.Roles.Single(r => r.Value.Id.ToString() == role.RoleId).Value; if (!ctx.Member.Roles.Contains(dRole)) { await ctx.RespondAsync("You don't seem to have that role."); return; } await ctx.Member.RevokeRoleAsync(dRole, "[Kasumi] Removing self-assignable role."); await ctx.RespondAsync($"You should no longer have the `{dRole.Name}` role."); } }
public async Task <ActionResult <RolesModel> > aPost(RolesModel payload) { using (var rc = new RolesContext()){ rc.Rolmc.Add(payload); await rc.SaveChangesAsync(); } return(Ok(payload)); }
public void BeforeEachTestAfterBase() { var context = new RolesContext <IdentityRole>(Roles); var roleStore = new RoleStore <IdentityRole>(context); manager = new RoleManager <IdentityRole>(roleStore); role = new ExtendedIdentityRole { Name = "admin" }; }
public void BeforeEachTest() { var client = new MongoClient("mongodb://localhost:27017"); Database = client.GetDatabase("identity-testing"); Users = Database.GetCollection <IdentityUser>("users"); Roles = Database.GetCollection <IdentityRole>("roles"); RolesContext = new RolesContext <IdentityRole>(Roles); UsersContext = new UsersContext <IdentityUser>(Users); Database.DropCollectionAsync("users").Wait(); Database.DropCollectionAsync("roles").Wait(); }
public async Task <ActionResult <RolesModel> > aGet(int?id) { using (var rc = new RolesContext()){ if (id == null) { var roles = rc.Rolmc.ToList(); return(Ok(roles)); } var aw = await rc.Rolmc.FindAsync(id); /*Buscar que rayos hace esto xd*/ return(NotFound(aw)); } }
public async Task <ActionResult <RolesModel> > aDel(int id) { using (var rc = new RolesContext()) { var aw = await rc.Rolmc.FindAsync(id); if (aw == null) { return(NotFound()); } rc.Rolmc.Remove(aw); await rc.SaveChangesAsync(); return(Ok(aw)); } }
public async Task AddCommand(CommandContext ctx, DiscordRole role, [RemainingText] string name) { using (var db = new RolesContext()) { var dbRole = new AssignableRole { Name = name, RoleId = role.Id.ToString(), ServerId = ctx.Guild.Id.ToString() }; db.AssignableRoles.Add(dbRole); await db.SaveChangesAsync(); await ctx.RespondAsync("Role added successfully."); } }
public async Task <ActionResult <RolesModel> > aPut(int id, [FromBody] RolesModel payload) { using (var rc = new RolesContext()) { var aw = await rc.Rolmc.FindAsync(id); if (aw == null) { return(BadRequest("id not found")); } /* Selecciona la "lista" del id (parametros del id) */ aw.nombrerol = payload.nombrerol; rc.Update(aw); await rc.SaveChangesAsync(); return(Ok(aw)); } }
public AdminService(IConfiguration config, IMapper mapper) { _mapper = mapper; var configEnumerable = config.AsEnumerable(); var connectionString = configEnumerable.FirstOrDefault(item => item.Key == "connectionString").Value; if (string.IsNullOrWhiteSpace(connectionString)) { return; } var optionsBuilder = new DbContextOptionsBuilder <RolesContext>(); optionsBuilder.UseSqlServer(connectionString); optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll); _rolesContext = new RolesContext(optionsBuilder.Options); }
public async Task DeleteCommand(CommandContext ctx, [RemainingText] string name) { using (var db = new RolesContext()) { var role = db.AssignableRoles .Where(r => r.ServerId == ctx.Guild.Id.ToString()) .Single(r => r.Name == name); if (role == null) { await ctx.RespondAsync("I couldn't find a role in this server by that name."); return; } db.AssignableRoles.Remove(role); await db.SaveChangesAsync(); await ctx.RespondAsync("Removed that role successfully. It has not been taken from any users that have it, though."); } }
public async Task ListCommand(CommandContext ctx) { using (var db = new RolesContext()) { var roles = db.AssignableRoles .Where(r => r.ServerId == ctx.Guild.Id.ToString()); if (!roles.Any()) { await ctx.RespondAsync("There are no roles available in this server."); return; } string output = ""; foreach (var role in roles) { output += $"`{role.Name}` "; } await ctx.RespondAsync($"Available roles: {output}"); } }
public RoleController(RolesContext context) { _context = context; }
public RolesController(RolesContext _context) { context = _context; }