public async Task <GameListResponse> ExecuteAsync(string genre)
        {
            var gameListResponse = new GameListResponse();

            try
            {
                Log.Information("Retrieving game Genre : [{Genre}]", genre);

                var games = (await Repository.FindAsync(g => string.Equals(g.Genre, genre, StringComparison.CurrentCultureIgnoreCase)))?.ToArray();
                if (games == null)
                {
                    var exception = new Exception($"No game found by Genre : [{genre}].");
                    Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message);
                    HandleErrors(gameListResponse, exception, 404);
                }
                else
                {
                    //NOTE: Not sure if I want to do something like AutoMapper for this example.
                    gameListResponse.Games      = games;
                    gameListResponse.StatusCode = 200;
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Failed to get Game for Genre [{Genre}].", genre);
                HandleErrors(gameListResponse, exception);
            }
            return(gameListResponse);
        }
Exemplo n.º 2
0
        public async Task <GameListResponse> ExecuteAsync()
        {
            Log.Information("Retrieving Games List...");
            var gameListResponse = new GameListResponse();

            try
            {
                var games = (await Repository.GetAllAsync())?.ToArray();

                if (games == null || !games.Any())
                {
                    var exception = new Exception("No Games Returned.");
                    Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message);
                    HandleErrors(gameListResponse, exception, 404);
                }
                else
                {
                    gameListResponse = new GameListResponse
                    {
                        Games      = games,
                        StatusCode = 200
                    };
                    var count = games.Length;
                    Log.Information("Retrieved [{Count}] Games.", count);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception, "Failed to get All Games List.");
                HandleErrors(gameListResponse, exception);
            }
            return(gameListResponse);
        }
Exemplo n.º 3
0
        public GameListResponse GetGameList(GameListRequest gamesListRequest)
        {
            string           content  = JsonConvert.SerializeObject(gamesListRequest);
            string           path     = string.Format("/gamestatistics/{0}/GameList", _vendorName);
            string           response = Post(content, path);
            GameListResponse gameConfiguratuionsResponse = JsonConvert.DeserializeObject <GameListResponse>(response);

            return(gameConfiguratuionsResponse);
        }
Exemplo n.º 4
0
        public IActionResult Index(GameListRequest gameListRequestModel)
        {
            // HttpManager goo = new HttpManager();
            //  goo.GetAll();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            GameListResponse response = _gameListResponseBuilder.GetResponse(gameListRequestModel, User);

            return(View(response));
        }
Exemplo n.º 5
0
        public string GetGameList()
        {
            GameListResponse         response         = new GameListResponse();
            GameListRequestProcessor requestProcessor = new GameListRequestProcessor();

            if (requestProcessor.ProcessRequest(
                    ApplicationConstants.CONNECTION_STRING,
                    Application,
                    out response.result))
            {
                response.game_list = requestProcessor.GameList;
                response.result    = SuccessMessages.GENERAL_SUCCESS;
            }

            return(JSONUtilities.SerializeJSONResponse <GameListResponse>(response));
        }