public virtual ActionResult Search(PlayedGamesFilterViewModel filter, ApplicationUser currentUser) { var playedGameFilter = new PlayedGameFilter { EndDateGameLastUpdated = filter.DatePlayedEnd == null ? null : filter.DatePlayedEnd.Value.ToString("yyyy-MM-dd"), GamingGroupId = currentUser.CurrentGamingGroupId, StartDateGameLastUpdated = filter.DatePlayedStart == null ? null : filter.DatePlayedStart.Value.ToString("yyyy-MM-dd"), GameDefinitionId = filter.GameDefinitionId }; var searchResults = playedGameRetriever.SearchPlayedGames(playedGameFilter); var playedGamesDetails = searchResults.Select(searchResult => new PlayedGameDetailsViewModel { DatePlayed = searchResult.DatePlayed, GameDefinitionId = searchResult.GameDefinitionId, GameDefinitionName = searchResult.GameDefinitionName, GamingGroupId = searchResult.GamingGroupId, GamingGroupName = searchResult.GamingGroupName, Notes = searchResult.Notes, PlayedGameId = searchResult.PlayedGameId, UserCanEdit = true, WinnerType = PlayedGameDetailsViewModelBuilder.CalculateWinnerType(searchResult.PlayerGameResults.Select(x => x.GameRank).ToList()), PlayerResults = searchResult.PlayerGameResults.Select(playerResult => new GameResultViewModel { DatePlayed = searchResult.DatePlayed, GameDefinitionId = searchResult.GameDefinitionId, GameDefinitionName = searchResult.GameDefinitionName, GameRank = playerResult.GameRank, NemeStatsPointsAwarded = playerResult.NemeStatsPointsAwarded, PlayedGameId = searchResult.PlayedGameId, PlayerId = playerResult.PlayerId, PlayerName = playerResult.PlayerName }).ToList() }).ToList(); var viewModel = new SearchViewModel { Filter = { DatePlayedEnd = filter.DatePlayedEnd, DatePlayedStart = filter.DatePlayedStart, GameDefinitionId = filter.GameDefinitionId }, GameDefinitions = GetAllGameDefinitionsForCurrentGamingGroup(currentUser.CurrentGamingGroupId), PlayedGames = new PlayedGamesViewModel { PlayedGameDetailsViewModels = playedGamesDetails, UserCanEdit = true, PanelTitle = string.Format("{0} Results", playedGamesDetails.Count), GamingGroupId = currentUser.CurrentGamingGroupId, ShowSearchLinkInResultsHeader = false } }; return(View(MVC.PlayedGame.Views.Search, viewModel)); }
private void SetItAllUp(WinnerTypes winnerType) { Stack <int> gameRankStack = new Stack <int>(); if (winnerType == WinnerTypes.PlayerWin) { gameRankStack.Push(1); gameRankStack.Push(2); gameRankStack.Push(3); } else if (winnerType == WinnerTypes.TeamLoss) { gameRankStack.Push(2); gameRankStack.Push(2); gameRankStack.Push(2); } else if (winnerType == WinnerTypes.TeamWin) { gameRankStack.Push(1); gameRankStack.Push(1); gameRankStack.Push(1); } this.gamingGroup = new GamingGroup { Id = this.gamingGroupId, Name = "gaming group name" }; this.playedGame = new PlayedGame { Id = 11111, GameDefinition = new GameDefinition(), GamingGroup = this.gamingGroup, GameDefinitionId = 2222, PlayerGameResults = new List <PlayerGameResult>(), GamingGroupId = this.gamingGroupId, Notes = "some notes" + Environment.NewLine + "some notes on a separate line" }; this.playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 3, Id = 1, PlayedGameId = this.playedGame.Id, PlayerId = 1 }); this.playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 2, Id = 2, PlayedGameId = this.playedGame.Id, PlayerId = 2 }); this.playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 1, Id = 3, PlayedGameId = this.playedGame.Id, PlayerId = 3, PlayedGame = new PlayedGame() { GameDefinition = new GameDefinition() { Id = 135, Name = "Test game name" } } }); this.detailsBuilder = MockRepository.GenerateMock <IGameResultViewModelBuilder>(); this.builder = new PlayedGameDetailsViewModelBuilder(this.detailsBuilder); int totalPlayerGameResults = this.playedGame.PlayerGameResults.Count; for (int i = 0; i < totalPlayerGameResults; i++) { this.detailsBuilder.Expect( x => x.Build(this.playedGame.PlayerGameResults[i])) .Repeat .Once() .Return(new GameResultViewModel() { PlayerId = this.playedGame.PlayerGameResults[i].PlayerId }); } this.currentUser = new ApplicationUser() { CurrentGamingGroupId = this.gamingGroupId }; this.actualViewModel = this.builder.Build(this.playedGame, this.currentUser); }