Beispiel #1
0
        public PlanetJSONConverter(Planet planet, star_wars_apiContext context)
        {
            this.id             = planet.id;
            this.created        = planet.created;
            this.edited         = planet.edited;
            this.climate        = planet.climate;
            this.diameter       = planet.diameter;
            this.gravity        = planet.gravity;
            this.name           = planet.name;
            this.orbitalPeriod  = planet.orbitalPeriod;
            this.population     = planet.population;
            this.rotationPeriod = planet.rotationPeriod;
            this.surfaceWater   = planet.surfaceWater;
            this.population     = planet.population;
            this.terrain        = planet.terrain;
            this.filmIds        = new List <int>();
            this.residentIds    = new List <int>();

            List <FilmPlanet> filmPlanets = context.FilmPlanet.Where(b => b.PlanetId == planet.id).ToList();

            foreach (FilmPlanet film in filmPlanets)
            {
                this.filmIds.Add(film.FilmId);
            }
            List <PlanetCharacter> planetCharacters = context.PlanetCharacter.Where(b => b.planetId == planet.id).ToList();

            foreach (PlanetCharacter character in planetCharacters)
            {
                this.residentIds.Add(character.characterId);
            }
        }
        public StarshipJSONConverter(Starship starship, star_wars_apiContext context)
        {
            this.id               = starship.id;
            this.created          = starship.created;
            this.edited           = starship.edited;
            this.mglt             = starship.mglt;
            this.hyperdriveRating = starship.hyperdriveRating;
            this.starshipClass    = starship.starshipClass;
            this.cargoCapacity    = starship.cargoCapacity;
            this.consumables      = starship.consumables;
            this.costInCredits    = starship.costInCredits;
            this.crew             = starship.crew;
            this.length           = starship.length;
            this.manufacturer     = starship.manufacturer;
            this.model            = starship.model;
            this.name             = starship.name;
            this.passengers       = starship.passengers;
            this.filmIds          = new List <int>();
            this.pilotIds         = new List <int>();

            List <FilmStarship> filmStarships = context.FilmStarship.Where(b => b.StarshipId == starship.id).ToList();

            foreach (FilmStarship film in filmStarships)
            {
                this.filmIds.Add(film.FilmId);
            }

            List <StarshipCharacter> starshipCharacters = context.StarshipCharacter.Where(b => b.starshipId == starship.id).ToList();

            foreach (StarshipCharacter character in starshipCharacters)
            {
                this.pilotIds.Add(character.characterId);
            }
        }
        public VehicleJSONConverter(Vehicle Vehicle, star_wars_apiContext context)
        {
            this.id            = Vehicle.id;
            this.created       = Vehicle.created;
            this.edited        = Vehicle.edited;
            this.vehicleClass  = Vehicle.vehicleClass;
            this.cargoCapacity = Vehicle.cargoCapacity;
            this.consumables   = Vehicle.consumables;
            this.costInCredits = Vehicle.costInCredits;
            this.crew          = Vehicle.crew;
            this.length        = Vehicle.length;
            this.manufacturer  = Vehicle.manufacturer;
            this.model         = Vehicle.model;
            this.name          = Vehicle.name;
            this.passengers    = Vehicle.passengers;
            this.filmIds       = new List <int>();
            this.pilotIds      = new List <int>();

            List <FilmVehicle> filmVehicles = context.FilmVehicle.Where(b => b.VehicleId == Vehicle.id).ToList();

            foreach (FilmVehicle film in filmVehicles)
            {
                this.filmIds.Add(film.FilmId);
            }

            List <VehicleCharacter> vehicleCharacters = context.VehicleCharacter.Where(b => b.vehicleId == Vehicle.id).ToList();

            foreach (VehicleCharacter character in vehicleCharacters)
            {
                this.pilotIds.Add(character.characterId);
            }
        }
 public ChallengeOutput(Film film, star_wars_apiContext context)
 {
     this.filmName  = film.title;
     filmCharacters = new List <string>();
     foreach (FilmCharacter filmCharacter in film.characterIds)
     {
         Character character = context.Character.Find(filmCharacter.CharacterId);
         filmCharacters.Add(character.name);
     }
 }
        public SpeciesJSONConverter(Species species, star_wars_apiContext context)
        {
            this.id              = species.id;
            this.created         = species.created;
            this.edited          = species.edited;
            this.averageHeight   = species.averageHeight;
            this.averageLifespan = species.averageLifespan;
            this.classification  = species.classification;
            this.designation     = species.designation;
            this.homeworldId     = species.homeworldId;
            this.language        = species.language;
            this.name            = species.name;
            this.filmIds         = new List <int>();
            this.peopleIds       = new List <int>();
            this.eyeColors       = new List <string>();
            this.hairColors      = new List <string>();
            this.skinColors      = new List <string>();

            List <FilmSpecies> filmSpecies = context.FilmSpecies.Where(b => b.SpeciesId == species.id).ToList();

            foreach (FilmSpecies film in filmSpecies)
            {
                this.filmIds.Add(film.FilmId);
            }

            List <SpeciesCharacter> speciesCharacters = context.SpeciesCharacter.Where(b => b.speciesId == species.id).ToList();

            foreach (SpeciesCharacter character in speciesCharacters)
            {
                this.peopleIds.Add(character.characterId);
            }

            List <SpeciesEyeColor> speciesEyeColors = context.SpeciesEyeColor.Where(b => b.speciesId == species.id).ToList();

            foreach (SpeciesEyeColor eyeColor in speciesEyeColors)
            {
                this.eyeColors.Add(eyeColor.eyeColor);
            }

            List <SpeciesHairColor> speciesHairColors = context.SpeciesHairColor.Where(b => b.speciesId == species.id).ToList();

            foreach (SpeciesHairColor hairColor in speciesHairColors)
            {
                this.hairColors.Add(hairColor.hairColor);
            }

            List <SpeciesSkinColor> speciesSkinColors = context.SpeciesSkinColor.Where(b => b.speciesId == species.id).ToList();

            foreach (SpeciesSkinColor skinColor in speciesSkinColors)
            {
                this.skinColors.Add(skinColor.skinColor);
            }
        }
        public FilmJSONConverter(Film film, star_wars_apiContext context)
        {
            this.id           = film.id;
            this.created      = film.created;
            this.edited       = film.edited;
            this.director     = film.director;
            this.episodeId    = film.episodeId;
            this.openingCrawl = film.openingCrawl;
            this.producer     = film.producer;
            this.releaseDate  = film.releaseDate;
            this.title        = film.title;
            this.characterIds = new List <int>();
            this.planetIds    = new List <int>();
            this.speciesIds   = new List <int>();
            this.starshipIds  = new List <int>();
            this.vehicleIds   = new List <int>();

            List <FilmCharacter> filmCharacters = context.FilmCharacter.Where(b => b.FilmId == film.id).ToList();

            foreach (FilmCharacter character in filmCharacters)
            {
                this.characterIds.Add(character.CharacterId);
            }

            List <FilmPlanet> filmPlanets = context.FilmPlanet.Where(b => b.FilmId == film.id).ToList();

            foreach (FilmPlanet planet in filmPlanets)
            {
                this.planetIds.Add(planet.PlanetId);
            }

            List <FilmSpecies> filmSpecies = context.FilmSpecies.Where(b => b.FilmId == film.id).ToList();

            foreach (FilmSpecies species in filmSpecies)
            {
                this.speciesIds.Add(species.SpeciesId);
            }

            List <FilmStarship> filmStarship = context.FilmStarship.Where(b => b.FilmId == film.id).ToList();

            foreach (FilmStarship starship in filmStarship)
            {
                this.starshipIds.Add(starship.StarshipId);
            }

            List <FilmVehicle> filmVehicle = context.FilmVehicle.Where(b => b.FilmId == film.id).ToList();

            foreach (FilmVehicle vehicle in filmVehicle)
            {
                this.vehicleIds.Add(vehicle.VehicleId);
            }
        }
        public CharacterJSONConverter(Character character, star_wars_apiContext context)
        {
            this.id          = character.id;
            this.created     = character.created;
            this.edited      = character.edited;
            this.name        = character.name;
            this.height      = character.height;
            this.mass        = character.mass;
            this.hairColor   = character.hairColor;
            this.eyeColor    = character.eyeColor;
            this.birthYear   = character.birthYear;
            this.gender      = character.gender;
            this.homeworldId = character.homeworldId;
            this.filmIds     = new List <int>();
            this.speciesIds  = new List <int>();
            this.vehicleIds  = new List <int>();
            this.starshipIds = new List <int>();

            List <FilmCharacter> filmCharacters = context.FilmCharacter.Where(b => b.CharacterId == character.id).ToList();

            foreach (FilmCharacter film in filmCharacters)
            {
                this.filmIds.Add(film.FilmId);
            }

            List <SpeciesCharacter> speciesCharacters = context.SpeciesCharacter.Where(b => b.characterId == character.id).ToList();

            foreach (SpeciesCharacter species in speciesCharacters)
            {
                this.speciesIds.Add(species.speciesId);
            }

            List <VehicleCharacter> vehicleCharacters = context.VehicleCharacter.Where(b => b.characterId == character.id).ToList();

            foreach (VehicleCharacter vehicle in vehicleCharacters)
            {
                this.vehicleIds.Add(vehicle.vehicleId);
            }

            List <StarshipCharacter> starshipCharacters = context.StarshipCharacter.Where(b => b.characterId == character.id).ToList();

            foreach (StarshipCharacter starship in starshipCharacters)
            {
                this.starshipIds.Add(starship.starshipId);
            }
        }
        public Starship ToModel(star_wars_apiContext context)
        {
            Starship starship = context.Starship.Find(this.id);

            bool newObject = false;

            if (starship == null)
            {
                newObject = true;
                starship  = new Starship();
            }

            starship.id               = this.id;
            starship.created          = this.created;
            starship.edited           = this.edited;
            starship.mglt             = this.mglt;
            starship.hyperdriveRating = this.hyperdriveRating;
            starship.starshipClass    = this.starshipClass;
            starship.cargoCapacity    = this.cargoCapacity;
            starship.consumables      = this.consumables;
            starship.costInCredits    = this.costInCredits;
            starship.crew             = this.crew;
            starship.length           = this.length;
            starship.manufacturer     = this.manufacturer;
            starship.model            = this.model;
            starship.name             = this.name;
            starship.passengers       = this.passengers;
            starship.filmIds          = new List <FilmStarship>();
            starship.pilotIds         = new List <StarshipCharacter>();

            if (newObject == false)
            {
                // many-many mapping classes have the IDs as foreign keys - if the object does not yet exist it cannot be linked to other objects.
                foreach (int filmId in this.filmIds)
                {
                    if (context.Film.Find(filmId) != null)
                    {
                        FilmStarship filmStarship = context.FilmStarship.Find(filmId, this.id);
                        if (filmStarship == null)
                        {
                            starship.filmIds.Add(new FilmStarship(filmId, this.id));
                        }
                        else
                        {
                            starship.filmIds.Add(filmStarship);
                        }
                    }
                }

                foreach (int characterId in this.pilotIds)
                {
                    if (context.Character.Find(characterId) != null)
                    {
                        StarshipCharacter starshipCharacter = context.StarshipCharacter.Find(this.id, characterId);
                        if (starshipCharacter == null)
                        {
                            starship.pilotIds.Add(new StarshipCharacter(this.id, characterId));
                        }
                        else
                        {
                            starship.pilotIds.Add(starshipCharacter);
                        }
                    }
                }
            }
            return(starship);
        }
 public StarshipController(star_wars_apiContext _context)
 {
     context = _context;
     dbSet   = context.Starship;
 }
        public Film ToModel(star_wars_apiContext context)
        {
            Film film = context.Film.Find(this.id);

            bool newObject = false;

            if (film == null)
            {
                newObject         = true;
                film              = new Film();
                film.characterIds = new List <FilmCharacter>();
                film.planetIds    = new List <FilmPlanet>();
                film.speciesIds   = new List <FilmSpecies>();
                film.starshipIds  = new List <FilmStarship>();
                film.vehicleIds   = new List <FilmVehicle>();
            }

            film.id           = this.id;
            film.created      = this.created;
            film.edited       = this.edited;
            film.director     = this.director;
            film.episodeId    = this.episodeId;
            film.openingCrawl = this.openingCrawl;
            film.producer     = this.producer;
            film.releaseDate  = this.releaseDate;
            film.title        = this.title;

            if (newObject == false)
            {
                // many-many mapping classes have the IDs as foreign keys - if the object does not yet exist it cannot be linked to other objects.
                foreach (int characterId in this.characterIds)
                {
                    if (context.Character.Find(characterId) != null)
                    {
                        FilmCharacter filmCharacter = context.FilmCharacter.Find(this.id, characterId);
                        if (filmCharacter == null)
                        {
                            filmCharacter = new FilmCharacter(this.id, characterId);
                        }
                        if (film.characterIds.Contains(filmCharacter) == false)
                        {
                            film.characterIds.Add(filmCharacter);
                        }
                    }
                }

                foreach (int planetId in this.planetIds)
                {
                    if (context.Planet.Find(planetId) != null)
                    {
                        FilmPlanet filmPlanet = context.FilmPlanet.Find(this.id, planetId);
                        if (filmPlanet == null)
                        {
                            filmPlanet = new FilmPlanet(this.id, planetId);
                        }
                        if (film.planetIds.Contains(filmPlanet) == false)
                        {
                            film.planetIds.Add(filmPlanet);
                        }
                    }
                }

                foreach (int speciesId in this.speciesIds)
                {
                    if (context.Species.Find(speciesId) != null)
                    {
                        FilmSpecies filmSpecies = context.FilmSpecies.Find(this.id, speciesId);
                        if (filmSpecies == null)
                        {
                            filmSpecies = new FilmSpecies(this.id, speciesId);
                        }
                        if (film.speciesIds.Contains(filmSpecies) == false)
                        {
                            film.speciesIds.Add(filmSpecies);
                        }
                    }
                }

                foreach (int starshipId in this.starshipIds)
                {
                    if (context.Starship.Find(starshipId) != null)
                    {
                        FilmStarship filmStarship = context.FilmStarship.Find(this.id, starshipId);
                        if (filmStarship == null)
                        {
                            filmStarship = new FilmStarship(this.id, starshipId);
                        }
                        if (film.starshipIds.Contains(filmStarship) == false)
                        {
                            film.starshipIds.Add(filmStarship);
                        }
                    }
                }

                foreach (int vehicleId in this.vehicleIds)
                {
                    if (context.Vehicle.Find(vehicleId) != null)
                    {
                        FilmVehicle filmVehicle = context.FilmVehicle.Find(this.id, vehicleId);
                        if (filmVehicle == null)
                        {
                            filmVehicle = new FilmVehicle(this.id, vehicleId);
                        }
                        if (film.vehicleIds.Contains(filmVehicle) == false)
                        {
                            film.vehicleIds.Add(filmVehicle);
                        }
                    }
                }
            }
            return(film);
        }
 public VehicleController(star_wars_apiContext _context)
 {
     context = _context;
     dbSet   = context.Vehicle;
 }
 public FilmRepository(star_wars_apiContext context)
 {
     _context = context;
     dbSet    = _context.Film;
 }
        public Species ToModel(star_wars_apiContext context)
        {
            Species species = context.Species.Find(this.id);

            bool newObject = false;

            if (species == null)
            {
                newObject = true;
                species   = new Species();
            }

            species.id              = this.id;
            species.created         = this.created;
            species.edited          = this.edited;
            species.averageHeight   = this.averageHeight;
            species.averageLifespan = this.averageLifespan;
            species.classification  = this.classification;
            species.designation     = this.designation;
            species.homeworldId     = this.homeworldId;
            species.language        = this.language;
            species.name            = this.name;
            species.filmIds         = new List <FilmSpecies>();
            species.peopleIds       = new List <SpeciesCharacter>();
            species.eyeColors       = new List <SpeciesEyeColor>();
            species.hairColors      = new List <SpeciesHairColor>();
            species.skinColors      = new List <SpeciesSkinColor>();

            if (newObject == false)
            {
                // many-many mapping classes have the IDs as foreign keys - if the object does not yet exist it cannot be linked to other objects.
                foreach (int filmId in this.filmIds)
                {
                    if (context.Film.Find(filmId) != null)
                    {
                        FilmSpecies filmSpecies = context.FilmSpecies.Find(filmId, this.id);
                        if (filmSpecies == null)
                        {
                            species.filmIds.Add(new FilmSpecies(filmId, this.id));
                        }
                        else
                        {
                            species.filmIds.Add(filmSpecies);
                        }
                    }
                }

                foreach (int characterId in this.peopleIds)
                {
                    if (context.Character.Find(characterId) != null)
                    {
                        SpeciesCharacter speciesCharacter = context.SpeciesCharacter.Find(this.id, characterId);
                        if (speciesCharacter == null)
                        {
                            species.peopleIds.Add(new SpeciesCharacter(this.id, characterId));
                        }
                        else
                        {
                            species.peopleIds.Add(speciesCharacter);
                        }
                    }
                }

                foreach (string eyeColor in this.eyeColors)
                {
                    SpeciesEyeColor speciesEyeColor = context.SpeciesEyeColor.Find(this.id, eyeColor);
                    if (speciesEyeColor == null)
                    {
                        species.eyeColors.Add(new SpeciesEyeColor(this.id, eyeColor));
                    }
                    else
                    {
                        species.eyeColors.Add(speciesEyeColor);
                    }
                }

                foreach (string hairColor in this.hairColors)
                {
                    SpeciesHairColor speciesHairColor = context.SpeciesHairColor.Find(this.id, hairColor);
                    if (speciesHairColor == null)
                    {
                        species.hairColors.Add(new SpeciesHairColor(this.id, hairColor));
                    }
                    else
                    {
                        species.hairColors.Add(speciesHairColor);
                    }
                }

                foreach (string skinColor in this.skinColors)
                {
                    SpeciesSkinColor speciesSkinColor = context.SpeciesSkinColor.Find(this.id, skinColor);
                    if (speciesSkinColor == null)
                    {
                        species.skinColors.Add(new SpeciesSkinColor(this.id, skinColor));
                    }
                    else
                    {
                        species.skinColors.Add(speciesSkinColor);
                    }
                }
            }
            return(species);
        }
 public SpeciesController(star_wars_apiContext _context)
 {
     context = _context;
     dbSet   = context.Species;
 }
        public Character ToModel(star_wars_apiContext context)
        {
            Character character = context.Character.Find(this.id);

            bool newObject = false;

            if (character == null)
            {
                newObject = true;
                character = new Character();
            }

            character.id = this.id;
            if (newObject == true)
            {
                character.created = DateTime.Now;
            }
            else
            {
                character.created = this.created;
            }
            character.edited = DateTime.Now;
            if (this.name == null)
            {
                throw new ArgumentException("The character name is mandatory");
            }
            else
            {
                character.name = this.name;
            }
            character.height      = this.height;
            character.hairColor   = this.hairColor;
            character.eyeColor    = this.eyeColor;
            character.birthYear   = this.birthYear;
            character.gender      = this.gender;
            character.homeworldId = this.homeworldId;
            character.filmIds     = new List <FilmCharacter>();    //Mandatory - at least one
            character.speciesIds  = new List <SpeciesCharacter>(); //Mandatory - one only
            character.vehicleIds  = new List <VehicleCharacter>();
            character.starshipIds = new List <StarshipCharacter>();
            if (this.filmIds.Count <= 1)
            {
                throw new ArgumentException("The character must be linked to at least one film");
            }
            if (this.speciesIds.Count != 1)
            {
                throw new ArgumentException("The character must be linked to one and only one species");
            }

            if (newObject == false)
            {
                // many-many mapping classes have the IDs as foreign keys - if the object does not yet exist it cannot be linked to other objects.
                foreach (int filmId in this.filmIds)
                {
                    if (context.Film.Find(filmId) != null)
                    {
                        FilmCharacter filmCharacter = context.FilmCharacter.Find(filmId, this.id);
                        if (filmCharacter == null)
                        {
                            character.filmIds.Add(new FilmCharacter(filmId, this.id));
                        }
                        else
                        {
                            character.filmIds.Add(filmCharacter);
                        }
                    }
                }

                foreach (int speciesId in this.speciesIds)
                {
                    if (context.Species.Find(speciesId) != null)
                    {
                        SpeciesCharacter speciesCharacter = context.SpeciesCharacter.Find(speciesId, this.id);
                        if (speciesCharacter == null)
                        {
                            character.speciesIds.Add(new SpeciesCharacter(speciesId, this.id));
                        }
                        else
                        {
                            character.speciesIds.Add(speciesCharacter);
                        }
                    }
                }

                foreach (int vehicleId in this.vehicleIds)
                {
                    if (context.Vehicle.Find(vehicleId) != null)
                    {
                        VehicleCharacter vehicleCharacter = context.VehicleCharacter.Find(vehicleId, this.id);
                        if (vehicleCharacter == null)
                        {
                            character.vehicleIds.Add(new VehicleCharacter(vehicleId, this.id));
                        }
                        else
                        {
                            character.vehicleIds.Add(vehicleCharacter);
                        }
                    }
                }

                foreach (int starshipId in this.starshipIds)
                {
                    if (context.Starship.Find(starshipId) != null)
                    {
                        StarshipCharacter starshipCharacter = context.StarshipCharacter.Find(starshipId, this.id);
                        if (starshipCharacter == null)
                        {
                            character.starshipIds.Add(new StarshipCharacter(starshipId, this.id));
                        }
                        else
                        {
                            character.starshipIds.Add(starshipCharacter);
                        }
                    }
                }
            }
            return(character);
        }
 public FilmController(star_wars_apiContext _context)
 {
     context      = _context;
     dbSet        = context.Film;
     _filmService = new FilmService(context);
 }
        public Vehicle ToModel(star_wars_apiContext context)
        {
            Vehicle Vehicle = context.Vehicle.Find(this.id);

            bool newObject = false;

            if (Vehicle == null)
            {
                newObject = true;
                Vehicle   = new Vehicle();
            }

            Vehicle.id            = this.id;
            Vehicle.created       = this.created;
            Vehicle.edited        = this.edited;
            Vehicle.vehicleClass  = this.vehicleClass;
            Vehicle.cargoCapacity = this.cargoCapacity;
            Vehicle.consumables   = this.consumables;
            Vehicle.costInCredits = this.costInCredits;
            Vehicle.crew          = this.crew;
            Vehicle.length        = this.length;
            Vehicle.manufacturer  = this.manufacturer;
            Vehicle.model         = this.model;
            Vehicle.name          = this.name;
            Vehicle.passengers    = this.passengers;
            Vehicle.filmIds       = new List <FilmVehicle>();
            Vehicle.pilotIds      = new List <VehicleCharacter>();

            if (newObject == false)
            {
                // many-many mapping classes have the IDs as foreign keys - if the object does not yet exist it cannot be linked to other objects.
                foreach (int filmId in this.filmIds)
                {
                    if (context.Film.Find(filmId) != null)
                    {
                        FilmVehicle filmVehicle = context.FilmVehicle.Find(filmId, this.id);
                        if (filmVehicle == null)
                        {
                            Vehicle.filmIds.Add(new FilmVehicle(filmId, this.id));
                        }
                        else
                        {
                            Vehicle.filmIds.Add(filmVehicle);
                        }
                    }
                }

                foreach (int characterId in this.pilotIds)
                {
                    if (context.Character.Find(characterId) != null)
                    {
                        VehicleCharacter vehicleCharacter = context.VehicleCharacter.Find(this.id, characterId);
                        if (vehicleCharacter == null)
                        {
                            Vehicle.pilotIds.Add(new VehicleCharacter(this.id, characterId));
                        }
                        else
                        {
                            Vehicle.pilotIds.Add(vehicleCharacter);
                        }
                    }
                }
            }
            return(Vehicle);
        }
Beispiel #18
0
 public PlanetController(star_wars_apiContext _context)
 {
     context = _context;
     dbSet   = context.Planet;
 }
Beispiel #19
0
 public FilmService(star_wars_apiContext context)
 {
     _filmRepository = new FilmRepository(context);
 }
Beispiel #20
0
        public Planet ToModel(star_wars_apiContext context)
        {
            Planet planet = context.Planet.Find(this.id);

            bool newObject = false;

            if (planet == null)
            {
                newObject = true;
                planet    = new Planet();
            }

            planet.id             = this.id;
            planet.created        = this.created;
            planet.edited         = this.edited;
            planet.climate        = this.climate;
            planet.diameter       = this.diameter;
            planet.gravity        = this.gravity;
            planet.name           = this.name;
            planet.orbitalPeriod  = this.orbitalPeriod;
            planet.population     = this.population;
            planet.rotationPeriod = this.rotationPeriod;
            planet.surfaceWater   = this.surfaceWater;
            planet.population     = this.population;
            planet.terrain        = this.terrain;
            planet.filmIds        = new List <FilmPlanet>();
            planet.residentIds    = new List <PlanetCharacter>();

            if (newObject == false)
            {
                // many-many mapping classes have the IDs as foreign keys - if the object does not yet exist it cannot be linked to other objects.
                foreach (int filmId in this.filmIds)
                {
                    if (context.Film.Find(filmId) != null)
                    {
                        FilmPlanet filmPlanet = context.FilmPlanet.Find(filmId, this.id);
                        if (filmPlanet == null)
                        {
                            planet.filmIds.Add(new FilmPlanet(filmId, this.id));
                        }
                        else
                        {
                            planet.filmIds.Add(filmPlanet);
                        }
                    }
                }

                foreach (int characterId in this.residentIds)
                {
                    if (context.Character.Find(characterId) != null)
                    {
                        PlanetCharacter planetCharacter = context.PlanetCharacter.Find(this.id, characterId);
                        if (planetCharacter == null)
                        {
                            planet.residentIds.Add(new PlanetCharacter(this.id, characterId));
                        }
                        else
                        {
                            planet.residentIds.Add(planetCharacter);
                        }
                    }
                }
            }
            return(planet);
        }
 public CharacterController(star_wars_apiContext _context)
 {
     context = _context;
     dbSet   = context.Character;
 }