Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> UpdatePlanet([FromBody] Planet planet, int planetId)
        {
            var result = await _planetService.UpdatePlanet(planet);

            if (!result)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Exemplo n.º 3
0
 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));
     }
 }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdatePlanet([FromBody] Planet planet)
        {
            await _planetService.UpdatePlanet(planet);

            return(Ok());
        }