public async Task <IActionResult> PutAPODItem(long id, APODItem aPODItem)
        {
            if (id != aPODItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(aPODItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!APODItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <IEnumerable <APODItem> > > GetNasaData()
        {
            HttpResponseMessage response = await Client.GetAsync("https://api.nasa.gov/planetary/apod?api_key=ErinR37q35EL8MkJOwu2h8XxH0htwDk6cYRDGJ84");

            if (response.IsSuccessStatusCode)
            {
                string itemString = await response.Content.ReadAsStringAsync();

                APODItem item = JsonConvert.DeserializeObject <APODItem>(itemString);
                _context.APODItems.Add(item);
                await _context.SaveChangesAsync();
            }

            return(await _context.APODItems.ToListAsync());
        }