コード例 #1
0
        public ActionResult UpdatePlanet([FromBody] Planet planet)
        {
            try
            {
                using var _context = new PlanetServiceDBContext();
                var planetToUpdate = _context.Planets.FirstOrDefault(p => p.PlanetId == planet.PlanetId);
                if (planetToUpdate == null)
                {
                    return(NotFound());
                }

                planetToUpdate.Description  = planet.Description;
                planetToUpdate.CrewId       = planet.CrewId;
                planetToUpdate.PlanetStatus = planet.PlanetStatus;

                _context.SaveChanges();
                return(Ok());
            }
            catch (Exception ex)
            {
                //Some cool logging mechanism
                Console.Write("Error at updating the planet: " + ex.Message);
                return(StatusCode(500, "An error occurred"));
            }
        }
コード例 #2
0
 public ActionResult GetPlanets()
 {
     try
     {
         using var _context = new PlanetServiceDBContext();
         var planets = _context.Planets.ToList();
         return(Ok(planets));
     }
     catch (Exception ex)
     {
         //Some cool logging mechanism
         Console.Write("Error at getting the planets: " + ex.Message);
         return(StatusCode(500, "An error occurred"));
     }
 }