Ejemplo n.º 1
0
 public HttpResponseMessage GetPlanets()
 {
     try
     {
         var response = _planetService.GetAllPlanets();
         return(Request.CreateResponse(HttpStatusCode.OK, response));
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
     }
 }
Ejemplo n.º 2
0
        public async Task <Guid> GetPlanetByShuttleId([FromQuery] Guid shuttleId)
        {
            try
            {
                var planet = (await _planetService.GetAllPlanets(new string(""), new List <Guid>(), shuttleId))
                             .First();
                if (planet != null)
                {
                    return(planet.Id);
                }
            }
            catch (PlanetApiException exception)
            {
                exception.LogException(_logger);
                return(new Guid());
            }
            catch (Exception exception) when(exception.GetType() != typeof(PlanetApiException))
            {
                _logger.LogCritical(exception, "Unhandled unexpected exception while retrieving data in exports");
                return(new Guid());
            }

            return(new Guid());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAllPlanets()
        {
            // Get All planets
            var planets = await _planetService.GetAllPlanets();

            // Return 204 no content if list is empty
            if (planets.Count() == 0)
            {
                return(NoContent());
            }

            // Map to planets List Dto
            var planetsDto = Mapper.Map <IEnumerable <PlanetListDto> >(planets);

            return(Ok(planetsDto));
        }
Ejemplo n.º 4
0
 public async Task <List <Planet> > GetPlanet([FromQuery] string toSearch, [FromQuery] Guid[] guids,
                                              [FromQuery] int pagination = 50, [FromQuery] int skip = 0)
 {
     try
     {
         return(await _service.GetAllPlanets(toSearch, guids.ToList(), new Guid(), pagination, skip));
     }
     catch (PlanetApiException exception)
     {
         exception.LogException(_logger);
         return(null);
     }
     catch (Exception exception) when(exception.GetType() != typeof(PlanetApiException))
     {
         _logger.LogCritical(exception, "Unhandled unexpected exception while retrieving Planets");
         return(null);
     }
 }
 public IHttpActionResult GetPlanets()
 {
     try
     {
         var result = _planetService.GetAllPlanets();
         if (result != null && result.Any())
         {
             return(Ok(result));
         }
         return(NotFound());
     }
     catch (Exception ex)
     {
         var message = new HttpResponseMessage(HttpStatusCode.BadRequest)
         {
             Content = new StringContent(ex.Message)
         };
         throw new HttpResponseException(message);
     }
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> Planets()
        {
            IEnumerable <Planet> planets = await _planetService.GetAllPlanets();

            return(Ok(planets));
        }
Ejemplo n.º 7
0
 public IActionResult Index()
 {
     ViewBag.spaceships = _spaceshipService.GetSpaceship();
     return(View(_planetService.GetAllPlanets()));
 }