コード例 #1
0
        private City GetCityOfSuperhero(SuperheroJsonModel hero, Country countryToAdd)
        {
            string heroCity  = hero.City.Name;
            City   cityToAdd = this.cities.GetAllFiltered(c => c.Name == heroCity).FirstOrDefault();

            if (cityToAdd == null)
            {
                cityToAdd = new City()
                {
                    Name = heroCity, Country = countryToAdd
                };

                return(cityToAdd);
            }
            else
            {
                return(cityToAdd);
            }
        }
コード例 #2
0
        private Country AddCountryToDbIfItIsANewEntry(SuperheroJsonModel hero, Planet planetToAdd)
        {
            string  heroCountry  = hero.City.Country;
            Country countryToAdd = this.countries.GetAllFiltered(c => c.Name == heroCountry).FirstOrDefault();

            if (countryToAdd == null)
            {
                countryToAdd = new Country()
                {
                    Name = heroCountry, Planet = planetToAdd
                };
                this.countries.Add(countryToAdd);

                return(countryToAdd);
            }
            else
            {
                return(countryToAdd);
            }
        }
コード例 #3
0
        private Planet AddPlanetToDbIfItIsANewEntry(SuperheroJsonModel hero)
        {
            string heroPlanet  = hero.City.Planet;
            Planet planetToAdd = this.planets.GetAllFiltered(p => p.Name == heroPlanet).FirstOrDefault();

            if (planetToAdd == null)
            {
                planetToAdd = new Planet()
                {
                    Name = heroPlanet
                };
                this.planets.Add(planetToAdd);

                return(planetToAdd);
            }
            else
            {
                return(planetToAdd);
            }
        }