예제 #1
0
        public ActionResult Index(int id)
        {
            Entities.User viewedProfile = _selectUser.Execute(id);

            Int32 currentUserId = Authentication.Security.CurrentUserId;

            if (viewedProfile != null)
            {
                Entities.Models.Profile.Profile model = new Entities.Models.Profile.Profile();
                model.ViewedProfile = viewedProfile;
                model.MyProfile     = viewedProfile.UserId == currentUserId;

                Entities.Filters.GamePlayer.SelectForUser filter = new Entities.Filters.GamePlayer.SelectForUser();
                filter.UserId     = id;
                filter.PlayerType = Entities.Enums.GamePlayerType.Player;

                model.GameProfiles = _selectGamePlayer.Execute(filter);

                model.TotalPoints = filter.TotalPoints;

                TempData["showSignOut"] = model.MyProfile;

                return(View(model));
            }
            else
            {
                return(Redirect(string.Format("/Profile/{0}", currentUserId)));
            }
        }
예제 #2
0
        /// <summary>
        /// Select all the votes based on <paramref name="filter"/>
        /// </summary>
        /// <param name="filter">Filter used to select votes to kick</param>
        /// <returns>The list of votes</returns>
        public List <Entities.GamePlayerKickVote> Execute(Entities.Filters.GamePlayerKickVote.SelectForGame filter)
        {
            List <Entities.GamePlayerKickVote> votesToKick = _select.Execute(filter);

            List <Int32> userIds = votesToKick.Select(x => x.KickUserId).Distinct().ToList();

            List <Entities.User> users = _selectUser.Execute(userIds);

            foreach (Entities.GamePlayerKickVote vote in votesToKick)
            {
                vote.KickUser = users.Find(x => x.UserId == vote.KickUserId);
            }

            return(votesToKick);
        }
예제 #3
0
        public ActionResult Index(Int32 id)
        {
            String key = String.Format("Game_{0}_Passphrase", id);
            String leaveGameJobIdKey = String.Format("LeaveGame_{0}_JobId", id);
            String passphrase        = String.Empty;
            String jobId             = String.Empty;
            Int32  currentUserId     = Authentication.Security.CurrentUserId;

            if (Session[key] != null)
            {
                passphrase = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[key] as Byte[]), Session.SessionID));
            }

            if (Session[leaveGameJobIdKey] != null)
            {
                jobId = Encoding.ASCII.GetString(MachineKey.Unprotect((Session[leaveGameJobIdKey] as Byte[]), Session.SessionID));

                BackgroundJob.Delete(jobId);

                Session.Remove(leaveGameJobIdKey);
            }

            Entities.User user = _selectUser.Execute(currentUserId);

            Entities.JoinResponse response = _joinGame.Execute(id, user, passphrase, Entities.Enums.GamePlayerType.Player);

            if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.GameOver))
            {
                return(Redirect("/GameListing"));
            }

            if (response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.BadPassphrase) == false &&
                response.Result.HasFlag(Entities.Enums.Game.JoinResponseCode.FullGame) == false)
            {
                Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame();
                kickVoteFilter.GameID = id;

                List <Entities.GamePlayerKickVote> votes = _selectKickVotes.Execute(kickVoteFilter);
                IEnumerable <IGrouping <Int32, Entities.GamePlayerKickVote> > grouped = votes.GroupBy(x => x.KickUserId);

                Entities.Models.Game.Board.VoteToKick kickModel = null;

                List <Entities.Models.Game.Board.VoteToKick> votesToKick = new List <Entities.Models.Game.Board.VoteToKick>();

                foreach (IGrouping <Int32, Entities.GamePlayerKickVote> group in grouped)
                {
                    if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null)
                    {
                        kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser,
                                                                              group.Count(x => x.Vote),
                                                                              group.Count(x => !x.Vote));

                        votesToKick.Add(kickModel);
                    }
                }

                List <Entities.GameRound> completedRounds = _selectGameRounds.Execute(new Entities.Filters.GameRound.SelectCompleted(id));

                Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(response.Game, currentUserId,
                                                                                                      Entities.Enums.GamePlayerType.Player,
                                                                                                      votesToKick,
                                                                                                      completedRounds);

                return(View("~/Views/Game/Board/Index.cshtml", model));
            }
            else
            {
                return(Redirect(Url.Action("Index", "GameListing", new { id = id })));
            }
        }