コード例 #1
0
        public async Task <ActionResult> GetAllPlanets()
        {
            var model = new AllPlanetsViewModel();

            List <PlanetModel> planets = await starWarsApi.GetAllPlanetsAsync();

            planets = planets.OrderByDescending(o => o.PlanetDiameterDouble).ToList();
            model.AverageDiameter = planets
                                    .Where(o => o.PlanetDiameterDouble > 0)
                                    .Average(a => a.PlanetDiameterDouble);
            foreach (PlanetModel p in planets)
            {
                PlanetDetailsViewModel pdvm = new PlanetDetailsViewModel();
                int diameter = 0;
                int.TryParse(p.PlanetDiameter, out diameter);
                pdvm.Diameter     = diameter;
                pdvm.Population   = p.PlanetPopulation;
                pdvm.Name         = p.PlanetName;
                pdvm.Terrain      = p.PlanetTerrain;
                pdvm.LengthOfYear = p.PlanetOrbitalPeriod;
                model.Planets.Add(pdvm);
            }


            return(View(model));
        }
コード例 #2
0
        public IActionResult Index(int id)
        {
            PlanetObj planet = _getPlanetRepository.GetPlanet(id);
            PlanetDetailsViewModel Planet = new PlanetDetailsViewModel
            {
                Planet = planet
            };

            return(View(Planet));
        }
コード例 #3
0
        public PlanetDetailsViewModel ToPlanetDetailsViewModel()
        {
            var model = new PlanetDetailsViewModel();

            model.Name         = Name;
            model.Population   = Population;
            model.Diameter     = Diameter;
            model.Terrain      = Terrain;
            model.LengthOfYear = LengthOfYear;

            return(model);
        }
コード例 #4
0
        public async Task <PlanetDetailsViewModel> GetPlanetDetails(string url)
        {
            var apiPlanet = await _planetService.GetPlanetFromUrl(url);

            var planetDetails = new PlanetDetailsViewModel();

            planetDetails.name            = apiPlanet.name;
            planetDetails.climate         = apiPlanet.climate;
            planetDetails.diameter        = apiPlanet.diameter;
            planetDetails.films           = apiPlanet.films;
            planetDetails.gravity         = apiPlanet.gravity;
            planetDetails.orbital_period  = apiPlanet.orbital_period;
            planetDetails.population      = apiPlanet.population;
            planetDetails.residents       = apiPlanet.residents;
            planetDetails.rotation_period = apiPlanet.rotation_period;
            planetDetails.surface_water   = apiPlanet.surface_water;
            planetDetails.terrain         = apiPlanet.terrain;

            return(planetDetails);
        }