Exemplo n.º 1
0
        private static async Task KickMember(HttpContext ctx, ValourDB db, ulong planet_id, ulong target_id,
                                             [FromHeader] string authorization)
        {
            AuthToken auth = await ServerAuthToken.TryAuthorize(authorization, db);

            if (auth is null)
            {
                Results.Unauthorized();
                return;
            }

            ServerPlanet planet = await db.Planets
                                  .Include(x => x.Members.Where(x => x.User_Id == auth.User_Id || x.Id == target_id))
                                  .FirstOrDefaultAsync(x => x.Id == planet_id);

            if (planet is null)
            {
                ctx.Response.StatusCode = 404;
                await ctx.Response.WriteAsync($"Planet not found");

                return;
            }

            ServerPlanetMember member = planet.Members.FirstOrDefault(x => x.User_Id == auth.User_Id);
            ServerPlanetMember target = planet.Members.FirstOrDefault(x => x.Id == target_id);

            var result = await planet.TryKickMemberAsync(member, target, db);

            ctx.Response.StatusCode = result.Data;
            await ctx.Response.WriteAsync(result.Message);
        }