Esempio n. 1
0
        public async Task <IActionResult> OnGetAsync(int GroupId, int TeamId, string Message)
        {
            try
            {
                Group = await _context.GameGroups.Include(g => g.GameTeams).Where(g => g.Id == GroupId).SingleAsync();
            }
            catch
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find that Group" }));
            }
            try { Team = Group.GameTeams.Single(t => t.Id == TeamId); }
            catch { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We were not able to find that Team" })); }

            string BibleId = await GameTeam.GetValidBibleIdAsync(_context, null);

            Path = await _context.Paths.FindAsync(Group.PathId);

            if (Path == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Very Odd! We were not able to find the Path for this Group" }));
            }

            // This has bee moved to an View Component, as an attempt to address perf issues... no luck.
            //_ = await Path.AddCalculatedPropertiesAsync(_context);

            //if (Team.BoardState == (int)GameTeam.GameBoardState.StepSelect)
            //{
            //    Steps = await Team.GetTeamStepsAsync(_context, BibleId);
            //}
            UserMessage = GetUserMessage(Message);
            return(Page());
        }
        //[PageRemote(
        //    ErrorMessage = "Plese select a word that is NOT found in the text below",
        //    AdditionalFields = "__RequestVerificationToken",
        //    HttpMethod = "post",
        //    PageHandler = "CheckGuideWord"
        //)]
        //[BindProperty]
        //public string UserGuideWord { get; set; }

        public async Task <IActionResult> OnGetAsync(int GroupId, int TeamId, string Message)
        {
            try
            {
                Group = await _context.GameGroups.Include(g => g.GameTeams).Where(g => g.Id == GroupId).SingleAsync();
            }
            catch
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find that Group" }));
            }
            try { Team = Group.GameTeams.Single(t => t.Id == TeamId); }
            catch { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We were not able to find that Team" })); }

            string BibleId = await GameTeam.GetValidBibleIdAsync(_context, null);

            Path = await _context.Paths.FindAsync(Group.PathId);

            if (Path == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Very Odd! We were not able to find the Path for this Group" }));
            }

            CurrentStep = await _context.PathNodes.FindAsync(Team.CurrentStepId);

            _ = await CurrentStep.AddGenericStepPropertiesAsync(_context, BibleId);

            _ = await CurrentStep.AddPathStepPropertiesAsync(_context);

            CurrentStep.Verses = await CurrentStep.GetBibleVersesAsync(_context, BibleId, true, false);

            // Now let's add VerseText to our Step
            _ = CurrentStep.AddVerseText();

            ViewData["KeyWordSelectList"] = await Team.GetKeyWordSelectListAsync(_context, CurrentStep);

            if (Team.BoardState == (int)GameTeam.GameBoardState.WordSelectOffPath)
            {
                Message = "Your Team seems to have fallen off the path, try to get them back on";
            }

            UserMessage = GetUserMessage(Message);
            return(Page());
        }
        public async Task <IViewComponentResult> InvokeAsync(int GroupId, int TeamId)
        {
            List <PathNode> TeamSteps = new List <PathNode>();
            GameGroup       Group     = await _context.GameGroups.FindAsync(GroupId);

            GameTeam Team = await _context.GameTeams.FindAsync(TeamId);

            string BibleId = await GameTeam.GetValidBibleIdAsync(_context, null);

            Path Path = await _context.Paths.FindAsync(Group.PathId);

            _ = await Path.AddCalculatedPropertiesAsync(_context);

            if (Team.BoardState == (int)GameTeam.GameBoardState.StepSelect)
            {
                TeamSteps = await Team.GetTeamStepsAsync(_context, BibleId);
            }
            Team.Steps = TeamSteps;
            return(View(Team));
        }
        public async Task <IActionResult> OnGetAsync(int GroupId, int TeamId, int StepId)
        {
            Group = await _context.GameGroups.FindAsync(GroupId);

            if (Group == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find that Group" }));
            }
            Team = await _context.GameTeams.FindAsync(TeamId);

            if (Team == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We were not able to find that Team" }));
            }
            if (Team.GroupId != Group.Id)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! The Team and Group do not match" }));
            }
            string BibleId = await GameTeam.GetValidBibleIdAsync(_context, null);

            // Now let's check that StepId
            if (StepId == Team.CurrentStepId)
            {
                PathNode CurrentStep = await _context.PathNodes.FindAsync(Team.CurrentStepId);

                if (CurrentStep == null)
                {
                    return(RedirectToPage("/error", new { errorMessage = "That's Very Odd! We couldn't find Current Step" }));
                }
                _ = await CurrentStep.AddGenericStepPropertiesAsync(_context, BibleId);

                _ = await CurrentStep.AddPathStepPropertiesAsync(_context);

                // We have a winner! Let's update the Team Object
                _context.Attach(Team);
                Team.Modified = DateTime.Now;
                if (CurrentStep.FWStepId > 0)
                {
                    Team.CurrentStepId = CurrentStep.FWStepId;
                    Team.StepNumber    = Team.StepNumber + 1;
                    Team.BoardState    = (int)GameTeam.GameBoardState.WordSelect;
                }
                else
                {
                    Team.BoardState = (int)GameTeam.GameBoardState.Completed;
                }
                await _context.SaveChangesAsync();

                // We need to add the Quotes around the TeamID, then signal the StateChange
                string GroupName = "\"" + Team.Id.ToString() + "\"";
                await _hubContext.Clients.Group(GroupName).SendAsync("StateChange");

                return(RedirectToPage("Team", new { GroupId = Team.GroupId, TeamId = Team.Id, Message = "Good Job! You're on the right Path" }));
            }
            else
            {
                _context.Attach(Team);
                Team.Modified   = DateTime.Now;
                Team.BoardState = (int)GameTeam.GameBoardState.WordSelectOffPath;
                await _context.SaveChangesAsync();

                // We need to add the Quotes around the TeamID, then signal the StateChange
                string GroupName = "\"" + Team.Id.ToString() + "\"";
                await _hubContext.Clients.Group(GroupName).SendAsync("StateChange");

                return(RedirectToPage("Team", new { GroupId = Team.GroupId, TeamId = Team.Id, Message = "Uh Oh! You've drifted off Path" }));
            }
        }