public PlanetResidentsViewModel(string planetName)
        {
            string planetUrl = GetPlanetUrlByName(planetName);

            Residents = new List <ResidentSummary>();

            string     json   = SwApiAccess.ApiGetRequest(planetUrl);
            JsonPlanet planet = JsonConvert.DeserializeObject <JsonPlanet>(json);

            foreach (string residentUrl in planet.Residents)
            {
                json = SwApiAccess.ApiGetRequest(residentUrl);
                JsonResident resident = JsonConvert.DeserializeObject <JsonResident>(json);

                ResidentSummary residentSummary = new ResidentSummary
                {
                    Name      = resident.Name,
                    Height    = resident.Height,
                    Weight    = resident.Mass,
                    Gender    = resident.Gender,
                    HairColor = resident.HairColor,
                    EyeColor  = resident.EyeColor,
                    SkinColor = resident.SkinColor
                };

                Residents.Add(residentSummary);
            }

            Residents = Residents.OrderBy(r => r.Name).ToList();
        }
Ejemplo n.º 2
0
        public SinglePlanetViewModel(string planetId)
        {
            string apiEndpoint = "https://swapi.co/api/planets/" + planetId;

            string     json   = SwApiAccess.ApiGetRequest(apiEndpoint);
            JsonPlanet planet = JsonConvert.DeserializeObject <JsonPlanet>(json);

            this.Name                   = planet.Name;
            this.LengthOfDay            = planet.RotationPeriod;
            this.LengthOfYear           = planet.OrbitalPeriod;
            this.Diameter               = planet.Diameter;
            this.Climate                = planet.Climate;
            this.Gravity                = planet.Gravity;
            this.SurfaceWaterPercentage = planet.SurfaceWater;
            this.Population             = planet.Population;
        }