Beispiel #1
0
        public async Task <IActionResult> Create([Bind("id,nombre,descripcion")] Rol rol)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rol);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rol));
        }
Beispiel #2
0
 public async Task <ActionResult <RolesModel> > aPost(RolesModel payload)
 {
     using (var rc = new RolesContext()){
         rc.Rolmc.Add(payload);
         await rc.SaveChangesAsync();
     }
     return(Ok(payload));
 }
Beispiel #3
0
        public async Task <EditRoleResponse> EditRole(int roleID, Role newRole)
        {
            var response = new EditRoleResponse();

            try
            {
                var role = await _rolesContext.Roles.FirstAsync(x => x.Id == roleID);

                role.Name = newRole.Name;

                _rolesContext.Entry(role).State = EntityState.Modified;
                await _rolesContext.SaveChangesAsync();

                response.OperationSucceded = true;
                response.Message           = "Role editted successfully";
            }
            catch (Exception)
            {
                response.OperationSucceded = false;
            }

            return(response);
        }
Beispiel #4
0
        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));
            }
        }
Beispiel #5
0
        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.");
            }
        }
Beispiel #6
0
        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));
            }
        }
Beispiel #7
0
        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.");
            }
        }