public static void AddAnomalies(IEnumerable <AnomalyDto> anomalies)
 {
     using (var context = new MassDefectEntities())
     {
         foreach (var anomalyDto in anomalies)
         {
             if (anomalyDto.OriginPlanet == null || anomalyDto.TeleportPlanet == null)
             {
                 Console.WriteLine("Error: Invalid data");
             }
             else
             {
                 var originPlanet   = PlanetStore.GetPlanetByName(anomalyDto.OriginPlanet);
                 var teleportPlanet = PlanetStore.GetPlanetByName(anomalyDto.TeleportPlanet);
                 if (originPlanet == null || teleportPlanet == null)
                 {
                     Console.WriteLine("Error: Invalid data");
                 }
                 else
                 {
                     var anomaly = new Anomaly
                     {
                         OriginPlanetId   = originPlanet.Id,
                         TeleportPlanetId = teleportPlanet.Id
                     };
                     context.Anomalies.Add(anomaly);
                     Console.WriteLine($"Successfuly imported Anomaly between {originPlanet.Name} and {teleportPlanet.Name}");
                 }
             }
         }
         context.SaveChanges();
     }
 }
        public static void AddVictims(IEnumerable <VictimDto> anomalyVictims)
        {
            using (var context = new MassDefectEntities())
            {
                foreach (var victimDto in anomalyVictims)
                {
                    if (victimDto.Person == null)
                    {
                        Console.WriteLine("Error: Invalid data");
                    }
                    else
                    {
                        var person  = context.Persons.FirstOrDefault(p => p.Name == victimDto.Person);
                        var anomaly = context.Anomalies.FirstOrDefault(a => a.Id == victimDto.Id);

                        if (person == null || anomaly == null)
                        {
                            Console.WriteLine("Error: Invalid data");
                        }
                        else
                        {
                            context.Persons.Attach(person);
                            context.Anomalies.Attach(anomaly);
                            anomaly.Victims.Add(person);

                            Console.WriteLine($"Successfuly imported Victim {person.Name} to Anomaly {anomaly.Id}");
                        }
                    }
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public static void AddPersons(IEnumerable <PersonDto> persons)
 {
     using (var context = new MassDefectEntities())
     {
         foreach (var personDto in persons)
         {
             if (personDto.Name == null || personDto.HomePlanet == null)
             {
                 Console.WriteLine("Error: Invalid data");
             }
             else
             {
                 var planet = PlanetStore.GetPlanetByName(personDto.HomePlanet);
                 if (planet == null)
                 {
                     Console.WriteLine("Error: Invalid data");
                 }
                 else
                 {
                     var person = new Person
                     {
                         Name         = personDto.Name,
                         HomePlanetId = planet.Id
                     };
                     context.Persons.Add(person);
                     Console.WriteLine($"Successfuly imported person {person.Name}");
                 }
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public static void AddPlanets(IEnumerable <PlanetDto> planets)
        {
            using (var context = new MassDefectEntities())
            {
                foreach (var planetDto in planets)
                {
                    if (planetDto.Name == null || planetDto.Sun == null || planetDto.SolarSystem == null)
                    {
                        Console.WriteLine("Error: Invalid data.");
                    }
                    else
                    {
                        var solarSystem = SolarSystemStore.GetSystemByName(planetDto.SolarSystem);
                        var sun         = StarStore.GetStarByName(planetDto.Sun);

                        if (solarSystem == null || sun == null)
                        {
                            Console.WriteLine("Error: Invalid data.");
                        }
                        else
                        {
                            var planet = new Planet
                            {
                                Name          = planetDto.Name,
                                SunId         = sun.Id,
                                SolarSystemId = solarSystem.Id
                            };
                            context.Planets.Add(planet);
                            Console.WriteLine($"Successfully imported Planet {planet.Name}.");
                        }
                    }
                }
                context.SaveChanges();
            }
        }
        public static void AddStars(IEnumerable <StarDto> stars)
        {
            using (var context = new MassDefectEntities())
            {
                foreach (var starDto in stars)
                {
                    if (starDto.Name == null || starDto.SolarSystem == null)
                    {
                        Console.WriteLine("Error: Invalid data.");
                    }
                    else
                    {
                        var solarSystem = context.SolarSystems
                                          .FirstOrDefault(s => s.Name == starDto.SolarSystem);

                        if (solarSystem == null)
                        {
                            Console.WriteLine("Error: Invalid data.");
                            continue;
                        }
                        var star = new Star
                        {
                            Name          = starDto.Name,
                            SolarSystemId = solarSystem.Id
                        };
                        context.Stars.Add(star);
                        Console.WriteLine("Successfully add star");
                    }
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 6
0
 public static void AddSolarSystems(IEnumerable <SolarSystemDto> systems)
 {
     using (var context = new MassDefectEntities())
     {
         foreach (var star in systems)
         {
             if (star.Name == null)
             {
                 Console.WriteLine("Invalid Data");
             }
             else
             {
                 context.SolarSystems.Add(new SolarSystem {
                     Name = star.Name
                 });
                 Console.WriteLine($"Successfully imported Solar Systems");
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
        public static void AddAnomaliesWithVictims(List <AnomalyWithVictimsDto> anomalies)
        {
            using (var context = new MassDefectEntities())
            {
                foreach (var anomalyDto in anomalies)
                {
                    var originPlanet   = PlanetStore.GetPlanetByName(anomalyDto.OriginPlanet);
                    var teleportPlanet = PlanetStore.GetPlanetByName(anomalyDto.TeleportPlanet);

                    if (originPlanet == null || teleportPlanet == null)
                    {
                        Console.WriteLine("Error: Invalid data.");
                    }
                    else
                    {
                        var anomaly = new Anomaly
                        {
                            OriginPlanetId   = originPlanet.Id,
                            TeleportPlanetId = teleportPlanet.Id
                        };
                        context.Anomalies.Add(anomaly);

                        foreach (var victimName in anomalyDto.Victims)
                        {
                            var victim = context.People.FirstOrDefault(p => p.Name == victimName);

                            if (victim != null)
                            {
                                anomaly.Victims.Add(victim);
                            }
                        }
                    }
                }
                context.SaveChanges();
            }
        }