Esempio n. 1
0
        public List<PlayedGameSearchResult> SearchPlayedGames(PlayedGameFilter playedGameFilter)
        {
            var queryable = from playedGame in dataContext.GetQueryable<PlayedGame>()
                .OrderByDescending(game => game.DatePlayed)
                .ThenByDescending(game => game.DateCreated)
                select new PlayedGameSearchResult
                {
                    PlayedGameId = playedGame.Id,
                    GameDefinitionId = playedGame.GameDefinitionId,
                    GameDefinitionName = playedGame.GameDefinition.Name,
                    BoardGameGeekGameDefinitionId = playedGame.GameDefinition.BoardGameGeekGameDefinitionId,
                    GamingGroupId = playedGame.GamingGroupId,
                    GamingGroupName = playedGame.GamingGroup.Name,
                    Notes = playedGame.Notes,
                    DatePlayed = playedGame.DatePlayed,
                    DateLastUpdated = playedGame.DateCreated,
                    ApplicationLinkages = playedGame.ApplicationLinkages.Select(x => new ApplicationLinkage
                    {
                        ApplicationName = x.ApplicationName,
                        EntityId = x.EntityId
                    }).ToList(),
                    PlayerGameResults = playedGame.PlayerGameResults.Select(x => new PlayerResult
                    {
                        GameRank = x.GameRank,
                        NemeStatsPointsAwarded = x.NemeStatsPointsAwarded,
                        GameDurationBonusNemePoints = x.GameDurationBonusPoints,
                        GameWeightBonusNemePoints = x.GameWeightBonusPoints,
                        TotalPoints = x.TotalPoints,
                        PlayerId = x.PlayerId,
                        PlayerName = x.Player.Name,
                        PlayerActive = x.Player.Active,
                        PointsScored = x.PointsScored,
                        DatePlayed = x.PlayedGame.DatePlayed,
                        GameDefinitionId = x.PlayedGame.GameDefinitionId,
                        GameName = x.PlayedGame.GameDefinition.Name,
                        PlayedGameId = x.PlayedGameId
                    }).ToList()
                };

            queryable = AddSearchCriteria(playedGameFilter, queryable);

            var results = queryable.ToList();

            SortPlayerResultsWithinEachSearchResult(results);

            return results;
        }
Esempio n. 2
0
        private static IQueryable<PlayedGameSearchResult> AddSearchCriteria(PlayedGameFilter playedGameFilter, IQueryable<PlayedGameSearchResult> queryable)
        {
            if (playedGameFilter.GamingGroupId.HasValue)
            {
                queryable = queryable.Where(query => query.GamingGroupId == playedGameFilter.GamingGroupId.Value);
            }

            if (playedGameFilter.GameDefinitionId.HasValue)
            {
                queryable = queryable.Where(query => query.GameDefinitionId == playedGameFilter.GameDefinitionId.Value);
            }

            if (!string.IsNullOrEmpty(playedGameFilter.StartDateGameLastUpdated))
            {
                var startDate = ParseDateTime(playedGameFilter.StartDateGameLastUpdated);
                queryable = queryable.Where(query => query.DateLastUpdated >= startDate);
            }

            if (!string.IsNullOrEmpty(playedGameFilter.EndDateGameLastUpdated))
            {
                var endDate = ParseDateTime(playedGameFilter.EndDateGameLastUpdated);
                endDate = endDate.Date.AddDays(1).AddMilliseconds(-1);
                queryable = queryable.Where(query => query.DateLastUpdated <= endDate);
            }

            if (!string.IsNullOrEmpty(playedGameFilter.DatePlayedFrom))
            {
                var fromDate = ParseDateTime(playedGameFilter.DatePlayedFrom);
                queryable = queryable.Where(query => query.DatePlayed >= fromDate);
            }

            if (!string.IsNullOrEmpty(playedGameFilter.DatePlayedTo))
            {
                var toDate = ParseDateTime(playedGameFilter.DatePlayedTo);
                toDate = toDate.Date.AddDays(1).AddMilliseconds(-1);
                queryable = queryable.Where(query => query.DatePlayed <= toDate);
            }

            if (playedGameFilter.PlayerId.HasValue)
            {
                queryable = queryable.Where(query => query.PlayerGameResults.Any(x => x.PlayerId == playedGameFilter.PlayerId));
            }

            if (playedGameFilter.MaximumNumberOfResults.HasValue)
            {
                queryable = queryable.Take(playedGameFilter.MaximumNumberOfResults.Value);
            }

            if (!string.IsNullOrEmpty(playedGameFilter.ExclusionApplicationName))
            {
                queryable = queryable.Where(query => query.ApplicationLinkages.All(x => x.ApplicationName != playedGameFilter.ExclusionApplicationName));
            }

            if (!string.IsNullOrEmpty(playedGameFilter.InclusionApplicationName))
            {
                queryable = queryable.Where(query => query.ApplicationLinkages.Any(x => x.ApplicationName == playedGameFilter.InclusionApplicationName));

            }

            return queryable;
        }
        public void ItFiltersOnThePlayerId()
        {
            var filter = new PlayedGameFilter
            {
                PlayerId = EXPECTED_PLAYER_ID
            };

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            Assert.True(results.All(result => result.PlayerGameResults.Any(x => x.PlayerId == filter.PlayerId)));
        }
        public void ItFiltersOnTheInclusionExternalSourceName()
        {
            //--arrange
            var filter = new PlayedGameFilter
            {
                InclusionApplicationName = EXTERNAL_SOURCE_NAME
            };

            //--act
            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            //--assert
            Assert.True(results.All(result => result.ApplicationLinkages.Any(x => x.ApplicationName == EXTERNAL_SOURCE_NAME)));
        }
        public void ItFiltersOnTheGamingGroupId()
        {
            var filter = new PlayedGameFilter
            {
                GamingGroupId = EXPECTED_GAMING_GROUP_ID
            };

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            Assert.True(results.All(result => result.GamingGroupId == filter.GamingGroupId));
        }
        public void ItFiltersOnTheGameDefinitionId()
        {
            var filter = new PlayedGameFilter
            {
                GameDefinitionId = EXPECTED_GAME_DEFINITION_ID
            };

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            Assert.True(results.All(result => result.GameDefinitionId == filter.GameDefinitionId));
        }
        public void ItLimitsSearchResultsToTheMaximumSpecified()
        {
            const int MAX_RESULTS = 1;
            var filter = new PlayedGameFilter
            {
                MaximumNumberOfResults = MAX_RESULTS
            };

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            Assert.That(results.Count, Is.EqualTo(MAX_RESULTS));
        }
        public void ItThrowsAnInvalidDateFormatExceptionIfTheEndDateGameLastUpdatedIsntYYYYMMDD()
        {
            var filter = new PlayedGameFilter
            {
                EndDateGameLastUpdated = "2015-3-1"
            };
            var expectedExceptionMessage = new InvalidDateFormatException(filter.EndDateGameLastUpdated).Message;

            var actualException = Assert.Throws<InvalidDateFormatException>(() => autoMocker.ClassUnderTest.SearchPlayedGames(filter));

            Assert.That(actualException.Message, Is.EqualTo(expectedExceptionMessage));
        }
        public void ItFiltersOnDatePlayedTo()
        {
            var filter = new PlayedGameFilter
            {
                DatePlayedTo = DATE_MARCH.ToString("yyyy-MM-dd")
            };

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            Assert.That(results.Count, Is.EqualTo(1));
            Assert.True(results.All(x => x.DatePlayed <= DATE_MARCH));
        }
        public void ItFiltersOnEndDateGameLastUpdated()
        {
            var filter = new PlayedGameFilter
            {
                EndDateGameLastUpdated = DATE_MARCH.ToString("yyyy-MM-dd")
            };

            var results = autoMocker.ClassUnderTest.SearchPlayedGames(filter);

            Assert.That(results.Count, Is.EqualTo(1));
            Assert.True(results.All(x => x.DateLastUpdated.Date <= new DateTime(2015, 3, 1)));
        }
Esempio n. 11
0
        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 = searchResult.WinnerType,
                PlayerResults = searchResult.PlayerGameResults.Select(playerResult => new GameResultViewModel
                {
                    DatePlayed = searchResult.DatePlayed,
                    GameDefinitionId = searchResult.GameDefinitionId,
                    GameDefinitionName = searchResult.GameDefinitionName,
                    GameRank = playerResult.GameRank,
                    NemePointsSummary = new NemePointsSummaryViewModel(playerResult.NemeStatsPointsAwarded, playerResult.GameDurationBonusNemePoints, playerResult.GameWeightBonusNemePoints),
                    PlayedGameId = searchResult.PlayedGameId,
                    PlayerId = playerResult.PlayerId,
                    PlayerName = playerResult.PlayerName,
                    PointsScored = playerResult.PointsScored,
                    WinnerType = searchResult.WinnerType
                }).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,
                    GamingGroupId = currentUser.CurrentGamingGroupId,
                    ShowSearchLinkInResultsHeader = false
                }
            };
            return View(MVC.PlayedGame.Views.Search, viewModel);
        }