Exemplo n.º 1
0
        public async Task <IActionResult> SearchGameSessionsButton([FromBody] SearchGameSessionsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var eventsList = await _gameSessionRepository.SearchGameSessions(model);

            return(new JsonResult(eventsList));
        }
        public async Task <List <GameSessionViewModel> > SearchGameSessions(SearchGameSessionsViewModel model)
        {
            var searchParameter = new SearchParameters()
            {
                GameSessionName = model.SearchGameSessionName
            };

            if (model.SearchGameSessionDateFrom.HasValue)
            {
                searchParameter.StartDate = model.SearchGameSessionDateFrom.Value;
            }
            if (model.SearchGameSessionDateTo.HasValue)
            {
                searchParameter.EndDate = model.SearchGameSessionDateTo.Value;
            }
            var gameSessionList = await _db.GameSessions.SearchGameSession(searchParameter);

            var gameSessionViewModels = GameSessionMethods.GetListGameSessionsViewModel(gameSessionList.Where(x => x.IsCanceled == false).ToList());

            _logger.LogInformation(LoggingEvents.GetGameSessionList, "Returned {Count} GameSessions", gameSessionViewModels.Count());
            return(gameSessionViewModels);
        }