public async Task <bool> UpdatePlanet([FromQuery] Guid shuttleId, [FromQuery] Guid planetId, [FromQuery] int numberOfRobotsDelta) { try { if (shuttleId != Guid.Empty) // provide shuttleId to do anything { if (planetId != Guid.Empty) // provide planetId to visit a planet and numberOfRobots if wanted { var planet = (await _planetService.GetAllPlanets(new string(""), new List <Guid> { planetId })) .First(); planet.ShuttleId = shuttleId; if (numberOfRobotsDelta != 0) { planet.NumberOfRobots = planet.NumberOfRobots + numberOfRobotsDelta; } await _planetService.UpdatePlanet(planet); } else // don't provide a planetId to un-visit a planet { var planet = (await _planetService.GetAllPlanets(new string(""), new List <Guid>(), shuttleId)).First(); planet.ShuttleId = Guid.Empty; planet.NumberOfRobots = 0; await _planetService.UpdatePlanet(planet); } } } catch (PlanetApiException exception) { exception.LogException(_logger); return(false); } catch (Exception exception) when(exception.GetType() != typeof(PlanetApiException)) { _logger.LogCritical(exception, $"Unhandled unexpected exception while updating a Planet in exports controller"); return(false); } return(false); }
public async Task <ActionResult> UpdatePlanet([FromBody] Planet planet, int planetId) { var result = await _planetService.UpdatePlanet(planet); if (!result) { return(BadRequest()); } return(Ok()); }
public HttpResponseMessage UpdatePlanet(Planet planet) { try { var response = _planetService.UpdatePlanet(planet); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } }
public async Task <IActionResult> UpdatePlanet([FromBody] Planet planet) { await _planetService.UpdatePlanet(planet); return(Ok()); }