Exemplo n.º 1
0
        public async Task <GetCreditsResponse> Handle(GetCreditsRequest request, CancellationToken cancellationToken)
        {
            var response = await _http.GetCast(request);

            if (response.IsSuccessStatusCode)
            {
                var model = new GetCreditsResponse();

                using (var stream = await response.Content.ReadAsStreamAsync())
                {
                    model.Credits = await JsonSerializer.DeserializeAsync <Credits>(stream, DefaultJsonSettings.Settings);
                }

                model.Credits.Crew = model.Credits.Crew.Take(20).ToList();

                //if (request.Amount > 0)
                //{
                //    model.Credits.Cast = model.Credits.Cast.Skip(5).ToList();
                //} else
                //{
                //    model.Credits.Cast = model.Credits.Cast.Skip(5).Take(9).ToList();
                //}

                return(new GetCreditsResponse
                {
                    Credits = model.Credits
                });
            }
            else
            {
                throw new GetCreditsException("Error retrieving credits");
            }
        }