コード例 #1
0
        public async Task <IServiceResult <List <GameDetails>, ApiErrorModel> > GetGamesForSteamIdAsync(string steamId64)
        {
            var games = await _steamService.GetGamesFromProfileAsync(steamId64);

            //Example of an error that is unexpected and should not be displayed in the browser
            if (games == null)
            {
                var em = new ApiErrorModel()
                {
                    Errors = new List <string>()
                    {
                        $"Failed to find games for Steam Id: {steamId64}"
                    },
                    Type = ApiErrorModel.TYPE_SILENT_ERROR
                };
                return(ServiceResultFactory.Error <List <GameDetails>, ApiErrorModel>(em));
            }

            //Type of error that is expected and should be relayed back to the client as a toast message
            if (games.Count == 0)
            {
                var em = new ApiErrorModel()
                {
                    Errors = new List <string>()
                    {
                        $"No games found for Steam Id: {steamId64}"
                    },
                    Type = ApiErrorModel.TYPE_TOAST_ERROR
                };

                return(ServiceResultFactory.Error <List <GameDetails>, ApiErrorModel>(em));
            }

            var returnValues = await _gameSearchService.GetAsync(games.Select(g => g.AppId).ToArray());


            return(ServiceResultFactory.Ok <List <GameDetails>, ApiErrorModel>(returnValues));
        }