public async Task RemovePerm(int index) { index -= 1; if (index < 0) { return; } try { Permissionv2 p; using (var uow = _db.UnitOfWork) { var config = uow.GuildConfigs.GcWithPermissionsv2For(Context.Guild.Id); var permsCol = new PermissionsCollection <Permissionv2>(config.Permissions); p = permsCol[index]; permsCol.RemoveAt(index); uow._context.Remove(p); await uow.CompleteAsync().ConfigureAwait(false); _service.UpdateCache(config); } await ReplyConfirmLocalized("removed", index + 1, Format.Code(p.GetCommand(Prefix, (SocketGuild)Context.Guild))).ConfigureAwait(false); } catch (IndexOutOfRangeException) { await ReplyErrorLocalized("perm_out_of_range").ConfigureAwait(false); } }
public async Task MovePerm(int from, int to) { from -= 1; to -= 1; if (!(from == to || from < 0 || to < 0)) { try { Permissionv2 fromPerm; using (var uow = _db.UnitOfWork) { var config = uow.GuildConfigs.GcWithPermissionsv2For(Context.Guild.Id); var permsCol = new PermissionsCollection <Permissionv2>(config.Permissions); var fromFound = from < permsCol.Count; var toFound = to < permsCol.Count; if (!fromFound) { await ReplyErrorLocalized("not_found", ++from).ConfigureAwait(false); return; } if (!toFound) { await ReplyErrorLocalized("not_found", ++to).ConfigureAwait(false); return; } fromPerm = permsCol[from]; permsCol.RemoveAt(from); permsCol.Insert(to, fromPerm); await uow.CompleteAsync().ConfigureAwait(false); _service.UpdateCache(config); } await ReplyConfirmLocalized("moved_permission", Format.Code(fromPerm.GetCommand(Prefix, (SocketGuild)Context.Guild)), ++from, ++to) .ConfigureAwait(false); return; } catch (Exception e) when(e is ArgumentOutOfRangeException || e is IndexOutOfRangeException) { } } await ReplyErrorLocalized("perm_out_of_range").ConfigureAwait(false); }