public async Task InvokeAsync(HttpContext context, UserManager <AppUser> userManager, ILogger <RequestInitiatorMiddleware> logger)
        {
            if (context.Request.Path.Value.Contains("/user/"))
            {
                RequestInitiator initiator = RequestInitiator.Unknown;
                if (context.User.Identity.IsAuthenticated)
                {
                    var querySegments = context.Request.Path.Value.Split("/");
                    if (querySegments.Length > 2)
                    {
                        string ownerName = querySegments[2];
                        var    owner     = await userManager.FindByNameAsync(ownerName);

                        if (owner == null)
                        {
                            Console.WriteLine(123);
                        }
                        var  ownerId            = owner.Id;
                        var  userId             = userManager.GetUserId(context.User);
                        bool isRequestedByOwner = ownerId == userId;
                        initiator = isRequestedByOwner ? RequestInitiator.Owner : RequestInitiator.Guest;
                    }
                }

                context.Request.QueryString = context.Request.QueryString.Add("initiator", initiator.ToString());
            }

            await _next.Invoke(context);
        }
Example #2
0
        public async Task <LobbyJoiningRequest[]> GetUserLobbiesJoiningRequestsAsync(Guid userId, RequestInitiator requestInitiator)
        {
            await using var mnpContext = _contextFactory.Create();

            return(await mnpContext
                   .LobbyJoiningRequests
                   .Include(r => r.User)
                   .Include(r => r.Lobby)
                   .ThenInclude(l => l.LobbyGames)
                   .ThenInclude(lg => lg.Game)
                   .Where(r => r.Lobby.LobbyPlayers
                          .Any(p => p.PlayerId == userId && p.IsCreator) && r.RequestInitiator == requestInitiator)
                   .AsNoTracking()
                   .ToArrayAsync());
        }