Example #1
0
        /// <summary>
        /// Returns whether or not a user is an admin for the given event
        /// </summary>
        /// <param name="thisEvent">The event that's being checked</param>
        /// <param name="puzzleServerContext">Current PuzzleServerContext</param>
        public async Task <bool> IsAdminForEvent(PuzzleServerContext dbContext, Event thisEvent)
        {
            if (!MayBeAdminOrAuthor)
            {
                return(false);
            }

            return(await dbContext.EventAdmins.Where(a => a.Admin.ID == ID && a.Event.ID == thisEvent.ID).AnyAsync());
        }
        /// <summary>
        /// Returns the PuzzleUser for the currently signed in player
        /// </summary>
        /// <param name="puzzlerServerContext">Current PuzzleServerContext</param>
        /// <param name="user">The claim for the user being checked</param>
        /// <param name="userManager">The UserManager for the current context</param>
        /// <returns>The user's PuzzleUser object</returns>
        public static async Task <PuzzleUser> GetPuzzleUserForCurrentUser(PuzzleServerContext dbContext, ClaimsPrincipal user, UserManager <IdentityUser> userManager)
        {
            if (userManager == null || dbContext == null)
            {
                //Default PageModel constructor used - cannot get current user.
                return(new PuzzleUser {
                    Name = String.Empty
                });
            }

            if (user == null)
            {
                return(null);
            }

            string userId = userManager.GetUserId(user);

            return(await dbContext.PuzzleUsers.Where(u => u.IdentityUserId == userId).FirstOrDefaultAsync());
        }
 /// <summary>
 /// Returns whether or not a user is an author for the given event
 /// </summary>
 /// <param name="thisEvent">The event that's being checked</param>
 /// <param name="puzzleServerContext">Current PuzzleServerContext</param>
 public async Task <bool> IsAuthorForEvent(PuzzleServerContext puzzleServerContext, Event thisEvent)
 {
     return(await puzzleServerContext.EventAuthors.Where(a => a.Author.ID == ID && a.Event.ID == thisEvent.ID).AnyAsync());
 }
 /// <summary>
 /// Returns the PuzzleUser for the given IdentityUser
 /// </summary>
 /// <param name="identityUserId">The string Id of an IdentityUser</param>
 /// <param name="dbContext">The current PuzzleServerContext</param>
 /// <returns>A PuzzleUser object that corresponds to the given IdentityUser</returns>
 public static async Task <PuzzleUser> GetPuzzleUser(string identityUserId, PuzzleServerContext dbContext)
 {
     return(await dbContext.PuzzleUsers.Where(user => user.IdentityUserId == identityUserId).FirstOrDefaultAsync());
 }
 /// <summary>
 /// Returns whether or not a user is a player in the given event
 /// </summary>
 /// <param name="thisEvent">The event that's being checked</param>
 /// <param name="puzzleServerContext">Current PuzzleServerContext</param>
 public async Task <bool> IsPlayerInEvent(PuzzleServerContext dbContext, Event thisEvent)
 {
     return(await dbContext.TeamMembers.Where(tm => tm.Member.ID == ID && tm.Team.Event.ID == thisEvent.ID).AnyAsync());
 }