public IActionResult PictureOfDay([Bind("Date")] PictureOfDayFilter pictureOfDayFilter) { if (pictureOfDayFilter.Date > DateTime.Now) { pictureOfDayFilter.Date = DateTime.Now; } var getPictureOfDayFilter = new GetPictureOfDayFilter(pictureOfDayFilter.Date); var pictureOfDayDto = _apodService.GetPictureOfDay(getPictureOfDayFilter).GetAwaiter().GetResult(); var pictureOfDayModel = new PictureOfDay { Copyright = pictureOfDayDto.Copyright, Date = pictureOfDayDto.Date, Explanation = pictureOfDayDto.Explanation, Hdurl = pictureOfDayDto.Hdurl, Media_type = pictureOfDayDto.Media_type, Service_version = pictureOfDayDto.Service_version, Title = pictureOfDayDto.Title, Url = pictureOfDayDto.Url }; return(View(pictureOfDayModel)); }
public async Task <PictureOfDay> GetPictureOfDay() { using var client = new HttpClient(); var response = await client.GetAsync("https://api.nasa.gov/planetary/apod?api_key=<SUA_NASA_KEY>"); var pictureOfDay = new PictureOfDay(); if (response.IsSuccessStatusCode) { pictureOfDay = await JsonSerializer.DeserializeAsync <PictureOfDay>(await response.Content.ReadAsStreamAsync()); } return(pictureOfDay); }