Esempio n. 1
0
        public async Task <IActionResult> FindAll([FromQuery] DecklistBrowserQueryParametersDTO queryParams)
        {
            if (!_decklistBrowserQueryParamsValidator.IsValid(queryParams))
            {
                return(BadRequest("Invalid params. Please report it to administrator."));
            }

            DateTime?statisticsFrom = null;
            DateTime?statisticsTo   = null;

            if (!string.IsNullOrEmpty(queryParams.StatisticsFromDate))
            {
                statisticsFrom = DateTime
                                 .ParseExact(
                    queryParams.StatisticsFromDate,
                    DateFormat.yyyy_MM_dd,
                    CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(queryParams.StatisticsToDate))
            {
                statisticsTo = DateTime
                               .ParseExact(
                    queryParams.StatisticsToDate,
                    DateFormat.yyyy_MM_dd,
                    CultureInfo.InvariantCulture);
            }

            var decklists = await _decklistService.FindAll(
                minNumberOfGames : queryParams.MinNumberOfGames,
                banlistId : queryParams.BanlistId,
                archetypeName : queryParams.ArchetypeName,
                statisticsFrom : statisticsFrom,
                statisticsTo : statisticsTo,
                orderByDescendingByNumberOfGames : queryParams.OrderByDescendingByNumberOfGames,
                wantedCardsInDeck : queryParams.WantedCardsInDeck);

            int numberOfResultsPerPage = _numberOfResultsHelper.GetNumberOfResultsPerPage(queryParams.NumberOfResults);
            var numberOfPages          = Convert.ToInt32(
                Math.Ceiling(
                    ((double)(decklists.Count()) / (double)(numberOfResultsPerPage))
                    )
                );

            var decklistsToActualPage = decklists
                                        .Skip(numberOfResultsPerPage * (queryParams.PageNumber - 1))
                                        .Take(numberOfResultsPerPage)
                                        .ToList();

            var decklistDtos = _decklistToDtoConverter.Convert(
                decklistsToActualPage,
                statisticsFrom,
                statisticsTo);

            return(new JsonResult(new DecklistBrowserResultsDTO(numberOfPages, decklistDtos)));
        }
Esempio n. 2
0
        public async Task <IActionResult> FindAll([FromQuery] ArchetypeBrowserQueryParams queryParams)
        {
            if (!_queryParamsValidator.IsValid(queryParams))
            {
                return(BadRequest("Invalid params. Please report it to administrator."));
            }

            DateTime?statisticsFrom = null;
            DateTime?statisticsTo   = null;

            if (!string.IsNullOrEmpty(queryParams.StatisticsFromDate))
            {
                statisticsFrom = DateTime
                                 .ParseExact(
                    queryParams.StatisticsFromDate,
                    DateFormat.yyyy_MM_dd,
                    CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(queryParams.StatisticsToDate))
            {
                statisticsTo = DateTime
                               .ParseExact(
                    queryParams.StatisticsToDate,
                    DateFormat.yyyy_MM_dd,
                    CultureInfo.InvariantCulture);
            }

            var archetypes = await _archetypeService.FindAllQuery(
                minNumberOfGames : queryParams.MinNumberOfGames,
                archetypeName : queryParams.ArchetypeName,
                statisticsFromDate : statisticsFrom,
                statisticsToDate : statisticsTo,
                includeCards : false,
                includeDecks : false,
                OrderByDescendingByNumberOfGames : queryParams.OrderByDescendingByNumberOfGames
                );

            int numberOfResultsPerPage = _numberOfResultsHelper.GetNumberOfResultsPerPage(queryParams.NumberOfResults);
            var numberOfPages          = Convert.ToInt32(
                Math.Ceiling(
                    ((double)(archetypes.Count()) / (double)(numberOfResultsPerPage))
                    )
                );

            var archetypesToActualPage = archetypes
                                         .Skip(numberOfResultsPerPage * (queryParams.PageNumber - 1))
                                         .Take(numberOfResultsPerPage)
                                         .ToList();

            var dtos = _archetypeToDtoConverter.Convert(archetypesToActualPage, statisticsFrom, statisticsTo);

            return(Ok(new ArchetypeBrowserResultsDTO(numberOfPages, dtos)));
        }
        public async Task <IActionResult> FindAll([FromQuery] BanlistBrowserQueryParams queryParams)
        {
            if (!_validator.IsValid(queryParams))
            {
                return(BadRequest("Invalid params. Please report it to administrator."));
            }

            DateTime?statisticsFrom = null;
            DateTime?statisticsTo   = null;

            if (!string.IsNullOrEmpty(queryParams.StatisticsFromDate))
            {
                statisticsFrom = DateTime
                                 .ParseExact(
                    queryParams.StatisticsFromDate,
                    DateFormat.yyyy_MM_dd,
                    CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(queryParams.StatisticsToDate))
            {
                statisticsTo = DateTime
                               .ParseExact(
                    queryParams.StatisticsToDate,
                    DateFormat.yyyy_MM_dd,
                    CultureInfo.InvariantCulture);
            }

            var banlists = await _banlistService
                           .FindAllQuery(
                minNumberOfGames : queryParams.MinNumberOfGames,
                formatOrName : queryParams.FormatOrName,
                statisticsFromDate : statisticsFrom,
                statisticsToDate : statisticsTo
                );

            int numberOfResultsPerPage = _numberOfResultsHelper.GetNumberOfResultsPerPage(queryParams.NumberOfResults);
            var numberOfPages          = Convert.ToInt32(
                Math.Ceiling(
                    ((double)(banlists.Count()) / (double)(numberOfResultsPerPage))
                    )
                );

            var banlistsToActualPage = banlists
                                       .Skip(numberOfResultsPerPage * (queryParams.PageNumber - 1))
                                       .Take(numberOfResultsPerPage)
                                       .ToList();

            var dtos = _banlistToDtoConverter
                       .Convert(banlistsToActualPage, statisticsFrom, statisticsTo);

            return(Ok(new BanlistBrowserResultsDTO(numberOfPages, dtos)));
        }