예제 #1
0
        public IActionResult Index(int gameId)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claims         = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            //Check if next turn is ready
            _playGame.CheckNextTurnReady(gameId);

            var notes = _unitOfWork.Note.GetAll(c => c.GameId == gameId && c.ApplicationUserId == claims.Value).ToList();

            PlayViewModel PlayVM = new PlayViewModel()
            {
                Character = _unitOfWork.GameUser.GetFirstOrDefault(filter: c => c.ApplicationUserId == claims.Value && c.GameId == gameId, includeProperties: "Game,ApplicationUser"),
                Opponents = _unitOfWork.GameUser.GetAll(filter: c => c.ApplicationUserId != claims.Value && c.GameId == gameId, includeProperties: "ApplicationUser", orderBy: q => q.OrderByDescending(c => c.IsAlive)),
                Notes     = notes,
                VoteList  = _unitOfWork.GameUser.GetAll(filter: c => c.GameId == gameId && c.IsAlive == true, includeProperties: "ApplicationUser").Select(c => c.ApplicationUser)
            };

            //Get the logs for the last turn
            PlayVM.Logs = _unitOfWork.Log.GetAll(c => c.GameId == gameId && c.Turn == PlayVM.Character.Game.TurnNumber - 1 && (c.Visible == SD.Everyone || c.Visible == PlayVM.Character.Role)).ToList();
            //PlayVM.Logs = logs.Where(c => c.Visible == SD.Everyone || c.Visible == PlayVM.Character.Role).ToList();

            //Get the already selected vote
            PlayVM.Vote = _unitOfWork.Vote.GetFirstOrDefault(c => c.ApplicationUserId == claims.Value && c.Turn == PlayVM.Character.Game.TurnNumber);
            //Get the list of already casted vote
            if (PlayVM.Character.Game.TurnType == SD.Night)
            {
                if (PlayVM.Character.Role == SD.Werewolf)
                {
                    //Get the list only for WEREWOLF for NIGHT
                    PlayVM.VoteCasted = _unitOfWork.Vote.GetAll(c => c.Role == SD.Werewolf && c.GameId == PlayVM.Character.GameId && c.Turn == PlayVM.Character.Game.TurnNumber);
                }
                else if (PlayVM.Character.Role == SD.Doctor)
                {
                    //Get the list only for DOCTOR for NIGHT
                    PlayVM.VoteCasted = _unitOfWork.Vote.GetAll(c => c.Role == SD.Doctor && c.GameId == PlayVM.Character.GameId && c.Turn == PlayVM.Character.Game.TurnNumber);
                }
                else if (PlayVM.Character.Role == SD.Seer)
                {
                    //Get the list only for SEER for NIGHT
                    PlayVM.VoteCasted = _unitOfWork.Vote.GetAll(c => c.Role == SD.Seer && c.GameId == PlayVM.Character.GameId && c.Turn == PlayVM.Character.Game.TurnNumber);
                }
            }
            else if (PlayVM.Character.Game.TurnType == SD.Day)
            {
                //get list for everyone during the Day
                PlayVM.VoteCasted = _unitOfWork.Vote.GetAll(c => c.GameId == PlayVM.Character.GameId && c.Turn == PlayVM.Character.Game.TurnNumber);
            }

            return(View(PlayVM));
        }