示例#1
0
        public async Task <ActionResult> GetPlanetTwentyTwo(CancellationToken cancellationToken, int planetid)
        {
            // TODO: Implement this controller action
            SinglePlanetViewModel vm = null;

            try
            {
                vm = await _starWarsService.GetPlanetTwentyTwoAsync(planetid, cancellationToken);
            }
            catch (NullReferenceException ex)
            {
                if (ex.Message.Contains("not found"))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }

                //potentially log error here and return 500
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            catch (Exception ex)
            {
                //potentially log error and rethrow error, or, in this case, just return 500
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            return(View(vm));
        }
        public ActionResult GetPlanetTwentyTwo(int planetid)
        {
            var model = new SinglePlanetViewModel();

            // TODO: Implement this controller action

            return(View(model));
        }
示例#3
0
        public SinglePlanetViewModel PlanetMapper(Planet planet)
        {
            var model  = new SinglePlanetViewModel();
            var config = new MapperConfiguration(cfg =>
                                                 cfg.CreateMap <Planet, SinglePlanetViewModel>()
                                                 .ForMember(dest => dest.Id, opt => opt.MapFrom(src => Regex.Match(src.Url, @"\d+").Value))
                                                 );

            var mapper = config.CreateMapper();

            model = mapper.Map <SinglePlanetViewModel>(planet);
            return(model);
        }
示例#4
0
        public SinglePlanetViewModel ToSinglePlanetViewModel()
        {
            var model = new SinglePlanetViewModel();

            model.Name                   = Name;
            model.LengthOfDay            = LengthOfDay;
            model.LengthOfYear           = LengthOfYear;
            model.Diameter               = Diameter;
            model.Climate                = Climate;
            model.Gravity                = Gravity;
            model.SurfaceWaterPercentage = SurfaceWaterPercentage;
            model.Population             = Population;

            return(model);
        }
示例#5
0
        /// <summary>
        /// Retrieve detailed information about a single planet identified by planetid.
        /// </summary>
        /// <param name="planetid">The id of the planet to be retrieved.</param>
        /// <returns>ActionResult</returns>
        public async Task <IActionResult> GetPlanetTwentyTwo(int planetid)
        {
            var planet = await _StarWarsService.GetPlanetAsync(planetid);

            var model = new SinglePlanetViewModel
            {
                Climate                = planet.Climate,
                Diameter               = planet.Diameter,
                Gravity                = planet.Gravity,
                LengthOfDay            = planet.LengthOfDay,
                LengthOfYear           = planet.LengthOfYear,
                Name                   = planet.Name,
                Population             = planet.Population,
                SurfaceWaterPercentage = planet.SurfaceWaterPercentage
            };

            return(View(model));
        }
示例#6
0
        public SinglePlanetViewModel GetPlanet(int planetId)
        {
            PlanetModel p = swapiAccessors.RequestPlanetById(planetId);

            SinglePlanetViewModel planet = p == null ? null :
                                           new SinglePlanetViewModel()
            {
                Name                   = p.Name,
                LengthOfDay            = p.RotationPeriod,
                LengthOfYear           = p.OrbitalPeriod,
                Diameter               = p.Diameter,
                Climate                = p.Climate,
                Gravity                = p.Gravity,
                SurfaceWaterPercentage = p.SurfaceWater,
                Population             = p.Population
            };

            return(planet);
        }
        public async Task <ActionResult> GetPlanetTwentyTwo(int planetid)
        {
            var model = new SinglePlanetViewModel();

            PlanetModel planet = await starWarsApi.GetPlanetByIdAsync(planetid);

            if (planet != null)
            {
                model.Climate                = planet.PlanetClimate;
                model.Diameter               = planet.PlanetDiameter;
                model.Gravity                = planet.PlanetGravity;
                model.LengthOfDay            = planet.PlanetDayLength;
                model.LengthOfYear           = planet.PlanetOrbitalPeriod;
                model.Name                   = planet.PlanetName;
                model.Population             = planet.PlanetPopulation;
                model.SurfaceWaterPercentage = planet.PlanetSurfaceWater;
            }
            return(View(model));
        }
示例#8
0
        public ActionResult GetPlanetTwentyTwo(int planetid)
        {
            var model = new SinglePlanetViewModel(planetid.ToString());

            return(View(model));
        }