예제 #1
0
        public async Task <IActionResult> EditUserGame(UserGameListingModel model)
        {
            // Added model validation
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("EditUserGame", "UserGame"));
            }

            var newUserGameContent = new NewUserGameModel
            {
                GamePlayedName = model.GameName,

                //Players detail
                User_01_Id   = model.User_01_Id,
                User_01_Team = model.User_01_Team,

                User_02_Id   = model.User_02_Id,
                User_02_Team = model.User_02_Team,

                //Score
                GameScoreUser01 = model.GameScoreUser01,
                GameScoreUser02 = model.GameScoreUser02,
            };

            var userGame = BuildUserGame(newUserGameContent);

            userGame.Id = model.Id;

            await _userGameService.EditUserGame(userGame);

            // SignalR send message to All that DB was updated
            await _hubContext.Clients.All.SendAsync("Notify", $"Created new UserGame at : {DateTime.Now}");

            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
        public IActionResult DeleteUserGame(int userGameId)
        {
            // Get game and Ask user if they sure they want to delete it
            var game    = _userGameService.GetById(userGameId);
            var user_01 = _userService.GetById(game.User_01_Id);
            var user_02 = _userService.GetById(game.User_02_Id);

            string user01Name = user_01.IsProfileDeleted ? "Profile Was Deleted" : user_01.UserName;
            string user02Name = user_02.IsProfileDeleted ? "Profile Was Deleted" : user_02.UserName;

            var model = new UserGameListingModel
            {
                Id = game.Id,

                GameName = game.GamePlayed.GameName,

                User_01_Name    = user01Name,
                User_01_Team    = game.User_01_Team,
                GameScoreUser01 = game.GameScoreUser01,

                User_02_Name    = user02Name,
                User_02_Team    = game.User_02_Team,
                GameScoreUser02 = game.GameScoreUser02,
            };

            return(View(model));
        }
예제 #3
0
        public IActionResult Index(int userGameId)
        {
            // When new game is created it is redirected to index page not Home
            //
            // TODO: Prepopulate form with data about games
            // Palyers names
            // Create view model to feed to the page
            var userGame = _userGameService.GetById(userGameId);
            var user_01  = _userService.GetById(userGame.User_01_Id);
            var user_02  = _userService.GetById(userGame.User_02_Id);

            var model = new UserGameListingModel
            {
                Id = userGame.Id,
                //Game played Date
                GamePlayedOn = userGame.GamePlayedOn,

                //Players detail
                User_01      = user_01,
                User_01_Team = userGame.User_01_Team,
                User_02      = user_02,
                User_02_Team = userGame.User_02_Team,

                // Game Name
                GameName = userGame.GamePlayed.GameName,

                //Score
                GameScore = userGame.GameScore,

                //Winner, “USER_01_Id”, “USER_02_Id”, “DRAW”
                Winner = userGame.Winner,
            };

            return(View(model));
        }
예제 #4
0
        public async Task <IActionResult> DeleteUserGame(UserGameListingModel model)
        {
            await _userGameService.DeleteUserGame(model.Id);

            // SignalR send message to All that DB was updated
            await _hubContext.Clients.All.SendAsync("Notify", $"Deleted UserGame at : {DateTime.Now}");

            return(RedirectToAction("Index", "Home"));
        }
예제 #5
0
        /**
         * Redirects to page which provides information on the games including a detailed match history
         */
        public IActionResult GameDetail(string gameId)
        {
            string          currentChampion = _monthlyWinnersService.GetPastMonthWinnerWithGameId(gameId);
            ApplicationUser champion;
            var             currentChampionName = "No Winner Last Month";

            // If champion exists and their profile was not deleted
            if (currentChampion != null)
            {
                champion = _userService.GetById(currentChampion);
                if (champion != null && !champion.IsProfileDeleted)
                {
                    currentChampionName = champion?.UserName;
                }
            }

            var game             = _game.GetById(Int32.Parse(gameId));
            var MatchHistoryData = _userGameService.getUserGamesByGameId(gameId);
            IEnumerable <UserGameListingModel> GameSpecificMatchHistory = MatchHistoryData.OrderByDescending((x) => x.GamePlayedOn).Select((userGameItem) =>
            {
                UserGameListingModel model1 = new UserGameListingModel
                {
                    Id = userGameItem.Id,
                    //Game played Date
                    GamePlayedOn = userGameItem.GamePlayedOn,

                    //Players detail
                    User_01      = _userService.GetById(userGameItem.User_01_Id),
                    User_01_Team = userGameItem.User_01_Team,
                    User_02      = _userService.GetById(userGameItem.User_02_Id),
                    User_02_Team = userGameItem.User_02_Team,

                    // Game Name
                    GameName = userGameItem.GamePlayed.GameName,

                    //Score
                    GameScore = userGameItem.GameScoreUser01 + " : " + userGameItem.GameScoreUser02,

                    //Winner, “USER_01_Id”, “USER_02_Id”, “DRAW”
                    Winner = userGameItem.Winner,
                };
                return(model1);
            });

            var model = new GameDetailModel
            {
                GameDetail = game,
                GameSpecificMatchHistory = GameSpecificMatchHistory,
                ReigningChampion         = currentChampionName
            };

            return(View(model));
        }
예제 #6
0
        public IActionResult EditUserGame(int userGameId)
        {
            // When new game is created it is redirected to index page not Home
            //
            // Palyers names
            // Create view model to feed to the page
            var userGame = _userGameService.GetById(userGameId);
            var user_01  = _userService.GetById(userGame.User_01_Id);
            var user_02  = _userService.GetById(userGame.User_02_Id);

            string user01Name = user_01.IsProfileDeleted ? "Profile Was Deleted" : user_01.UserName;
            string user02Name = user_02.IsProfileDeleted ? "Profile Was Deleted" : user_02.UserName;

            var model = new UserGameListingModel
            {
                Id = userGame.Id,
                //Game played Date
                GamePlayedOn = userGame.GamePlayedOn,

                //Players detail
                User_01_Id   = user_01.Id,
                User_01_Name = user01Name,
                User_01_Team = userGame.User_01_Team,

                User_02_Id   = user_02.Id,
                User_02_Name = user02Name,
                User_02_Team = userGame.User_02_Team,

                // Game Name
                GameName = userGame.GamePlayed.GameName,

                //Score
                GameScoreUser01 = userGame.GameScoreUser01,
                GameScoreUser02 = userGame.GameScoreUser02,

                //Winner, “USER_01_Id”, “USER_02_Id”, “DRAW”
                Winner = userGame.Winner,
            };

            return(View(model));
        }
예제 #7
0
        private IEnumerable <UserGameListingModel> GetMatchHistory(string gameId)
        {
            // prepare match history for specific game or overall game
            IEnumerable <UserGameListingModel> MatchHistoryList = _userGameService
                                                                  .getUserGamesByGameId(gameId)
                                                                  .OrderByDescending((x) => x.Id)
                                                                  .Take(5)
                                                                  .Select((userGameItem) =>
            {
                UserGameListingModel model1 = new UserGameListingModel
                {
                    Id = userGameItem.Id,
                    //Game played Date
                    GamePlayedOn = userGameItem.GamePlayedOn,

                    //Players detail
                    User_01      = _userService.GetById(userGameItem.User_01_Id),
                    User_01_Team = userGameItem.User_01_Team,
                    User_02      = _userService.GetById(userGameItem.User_02_Id),
                    User_02_Team = userGameItem.User_02_Team,

                    // Game Name
                    GameName = userGameItem.GamePlayed.GameName,

                    //
                    Apologised      = userGameItem.Apologised,
                    NeedToApologise = (Math.Abs(userGameItem.GameScoreUser01 - userGameItem.GameScoreUser02) >= 5)?true:false,

                    GamePlayedId = userGameItem.GamePlayed.Id,

                    //Score
                    GameScore = userGameItem.GameScoreUser01 + " : " + userGameItem.GameScoreUser02,

                    //Winner, “USER_01_Id”, “USER_02_Id”, “DRAW”
                    Winner = userGameItem.Winner,
                };
                return(model1);
            });

            return(MatchHistoryList);
        }
예제 #8
0
        public IActionResult Profile(string userID)
        {
            var MatchHistoryData = _userGameService.getUserGamesByUserId(userID);

            IEnumerable <UserGameListingModel> MatchHistory = MatchHistoryData.Select(userGame =>
            {
                UserGameListingModel ugameModel = new UserGameListingModel
                {
                    Id = userGame.Id,
                    //Game played Date
                    GamePlayedOn = userGame.GamePlayedOn,

                    //Players detail
                    User_01      = _userService.GetById(userGame.User_01_Id),
                    User_01_Team = userGame.User_01_Team,
                    User_02      = _userService.GetById(userGame.User_02_Id),
                    User_02_Team = userGame.User_02_Team,

                    // Game Name
                    GameName = userGame.GamePlayed.GameName,

                    Apologised      = userGame.Apologised,
                    NeedToApologise = (Math.Abs(userGame.GameScoreUser01 - userGame.GameScoreUser02) >= 5) ? true : false,

                    GamePlayedId = userGame.GamePlayed.Id,

                    // Score
                    GameScore = userGame.GameScoreUser01 + " : " + userGame.GameScoreUser02,

                    // Winner, “USER_01_Id”, “USER_02_Id”, “DRAW”
                    Winner = userGame.Winner,
                };
                return(ugameModel);
            }).OrderByDescending(game => game.Id);

            ApplicationUser        user         = _userService.GetById(userID);
            IEnumerable <UserGame> userGameList = _userGameService.GetAll();
            Dictionary <string, LeaderboardUserModel> gameStats = _gameService.GetAll()
                                                                  .Select(Game => new KeyValuePair <string, LeaderboardUserModel>(Game.GameName, new LeaderboardUserModel
            {
                UserId      = user.Id,
                UserName    = user.UserName,
                Wins        = _userGameService.getWinsByIdAndGameId(userGameList, user.Id, Game.Id.ToString()).ToString(),
                Draws       = _userGameService.getDrawsByIdAndGameId(userGameList, user.Id, Game.Id.ToString()).ToString(),
                Loses       = _userGameService.getLosesByIdAndGameId(userGameList, user.Id, Game.Id.ToString()).ToString(),
                Ratio       = _userGameService.getRatioWithIdAndGameId(userGameList, user.Id, Game.Id.ToString()).ToString(),
                MonthlyWins = _monthlyWinnersService.GetPastMonthAwardWithIdAndGameId(user.Id, Game.Id.ToString())
            })).ToDictionary(x => x.Key, x => x.Value);

            gameStats.Add("Overall", new LeaderboardUserModel
            {
                UserId      = user.Id,
                UserName    = user.UserName,
                Wins        = _userGameService.getWinsByIdAndGameId(userGameList, user.Id, "").ToString(),
                Draws       = _userGameService.getDrawsByIdAndGameId(userGameList, user.Id, "").ToString(),
                Loses       = _userGameService.getLosesByIdAndGameId(userGameList, user.Id, "").ToString(),
                Ratio       = _userGameService.getRatioWithIdAndGameId(userGameList, user.Id, "").ToString(),
                MonthlyWins = _monthlyWinnersService.GetPastMonthAwardWithIdAndGameId(user.Id, "overall")
            });


            var model = new UserProfileModel
            {
                User          = _userService.GetById(userID),
                UsersGames    = MatchHistory,
                GameStatistcs = gameStats
            };

            return(View(model));
        }