コード例 #1
0
 public void Create(Crews item)
 {
     dataSource.CrewsList.Add(item);
     dataSource.SaveChanges();
 }
コード例 #2
0
ファイル: FlightRepository.cs プロジェクト: Cheha/AirportMvc
 public void Add(Flight flight)
 {
     _db.Flights.Add(flight);
     _db.SaveChanges();
 }
コード例 #3
0
 public void Commit()
 {
     _ctx.SaveChanges();
 }
コード例 #4
0
        static public void Initialize(AirportContext context)
        {
            context.Database.Migrate();

            if (context.Flights.Any())
            {
                return; //already seeded
            }

            List <Pilot> pilots = new List <Pilot>()
            {
                new Pilot()
                {
                    Name = "PName1", Surname = "PSurname1", Experience = 3
                },
                new Pilot()
                {
                    Name = "PName2", Surname = "PSurname2", Experience = 4
                },
                new Pilot()
                {
                    Name = "PName3", Surname = "PSurname3", Experience = 9
                },
            };

            List <Stewardess> stewardesses = new List <Stewardess>()
            {
                new Stewardess()
                {
                    Name = "SName1", Surname = "SSurname1", DateOfBirth = new DateTime(1992, 10, 11)
                },
                new Stewardess()
                {
                    Name = "SName2", Surname = "SSurname2", DateOfBirth = new DateTime(1991, 10, 11)
                },
                new Stewardess()
                {
                    Name = "SName3", Surname = "SSurname3", DateOfBirth = new DateTime(1993, 10, 11)
                },
                new Stewardess()
                {
                    Name = "SName4", Surname = "SSurname4", DateOfBirth = new DateTime(1994, 10, 11)
                },
                new Stewardess()
                {
                    Name = "SName5", Surname = "SSurname5", DateOfBirth = new DateTime(1993, 11, 15)
                }
            };

            context.Pilots.AddRange(pilots);

            List <Crew> crews = new List <Crew>()
            {
                new Crew()
                {
                    Pilot        = pilots[1],
                    Stewardesses = new List <Stewardess>
                    {
                        stewardesses[1],
                        stewardesses[3]
                    }
                },
                new Crew()
                {
                    Pilot        = pilots[0],
                    Stewardesses = new List <Stewardess>
                    {
                        stewardesses[0],
                        stewardesses[2]
                    }
                },
                new Crew()
                {
                    Pilot        = pilots[2],
                    Stewardesses = new List <Stewardess>
                    {
                        stewardesses[4],
                    }
                }
            };


            context.Stewardesses.AddRange(stewardesses);

            crews.AddRange(crews);

            List <PlaneType> planeTypes = new List <PlaneType>()
            {
                new PlaneType()
                {
                    Model         = "Model1",
                    NumberOfSeats = 150,
                    LoadCapacity  = 1000
                },
                new PlaneType()
                {
                    Model         = "Model2",
                    NumberOfSeats = 125,
                    LoadCapacity  = 985
                },
                new PlaneType()
                {
                    Model         = "Model1",
                    NumberOfSeats = 189,
                    LoadCapacity  = 1010
                }
            };

            context.PlaneTypes.AddRange(planeTypes);

            List <Plane> planes = new List <Plane>()
            {
                new Plane()
                {
                    PlaneType   = planeTypes[1],
                    ReleaseDate = new DateTime(2008, 11, 18)
                },
                new Plane()
                {
                    PlaneType   = planeTypes[2],
                    ReleaseDate = new DateTime(2012, 2, 25)
                },
                new Plane()
                {
                    PlaneType   = planeTypes[1],
                    ReleaseDate = new DateTime(2011, 5, 10)
                },
                new Plane()
                {
                    PlaneType   = planeTypes[0],
                    ReleaseDate = new DateTime(2010, 8, 7)
                }
            };

            context.AddRange(planes);

            List <Ticket> tickets = new List <Ticket>()
            {
                new Ticket()
                {
                    FlightNumber = 2,
                    Price        = 258
                },
                new Ticket()
                {
                    FlightNumber = 1,
                    Price        = 257
                },
                new Ticket()
                {
                    FlightNumber = 2,
                    Price        = 256
                },
                new Ticket()
                {
                    FlightNumber = 3,
                    Price        = 255
                }
            };

            tickets.AddRange(tickets);

            List <Flight> flights = new List <Flight>()
            {
                new Flight()
                {
                    Tickets = new List <Ticket>()
                    {
                        tickets[1]
                    },
                    DepartureFrom   = "Kyiv",
                    Destination     = "Tokio",
                    ArrivalTime     = new DateTime(2018, 02, 03),
                    TimeOfDeparture = new DateTime(2018, 02, 02),
                },

                new Flight()
                {
                    Tickets = new List <Ticket>()
                    {
                        tickets[0],
                        tickets[2]
                    },
                    DepartureFrom   = "Dublin",
                    Destination     = "Paris",
                    ArrivalTime     = new DateTime(2017, 02, 03),
                    TimeOfDeparture = new DateTime(2017, 02, 02),
                },

                new Flight()
                {
                    Tickets = new List <Ticket>()
                    {
                        tickets[3]
                    },
                    DepartureFrom   = "Odesa",
                    Destination     = "Ternopil",
                    ArrivalTime     = new DateTime(2016, 02, 03),
                    TimeOfDeparture = new DateTime(2016, 02, 02),
                },
            };

            context.Flights.AddRange(flights);

            List <Departure> departures = new List <Departure>()
            {
                new Departure()
                {
                    Crew            = crews[1],
                    Flight          = flights[1],
                    Plane           = planes[2],
                    TimeOfDeparture = new DateTime(2017, 02, 03)
                },
                new Departure()
                {
                    Crew            = crews[2],
                    Flight          = flights[0],
                    Plane           = planes[1],
                    TimeOfDeparture = new DateTime(2018, 02, 03)
                },
                new Departure()
                {
                    Crew            = crews[0],
                    Flight          = flights[2],
                    Plane           = planes[0],
                    TimeOfDeparture = new DateTime(2016, 02, 03)
                }
            };

            context.Departures.AddRange(departures);

            context.SaveChanges();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <AirportContext>();

            optionsBuilder.UseLoggerFactory(MyLoggerFactory);
            optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["AirportDB"].ConnectionString);

            using (var db = new AirportContext(optionsBuilder.Options))
            {
                //CREATE
                var vol = new Vol {
                    CIE = "test",
                    LIG = "AZERTY"
                };
                db.Vols.Add(vol);
                db.SaveChanges();

                // Read
                var vol1 = db.Vols
                           .First();

                var baggage = new Bagage
                {
                    ID_VOL        = vol1.ID_VOL,
                    CODE_IATA     = "AZERTY",
                    DATE_CREATION = new DateTime(2012, 12, 25, 10, 30, 50)
                };
                db.Bagages.Add(baggage);
                db.SaveChanges();

                var baggage2 = new Bagage
                {
                    ID_VOL        = vol1.ID_VOL,
                    CODE_IATA     = "AERAZ",
                    DATE_CREATION = new DateTime(2012, 12, 25, 10, 30, 50)
                };
                db.Bagages.Add(baggage2);
                db.SaveChanges();

                // Read
                var bag = db.Bagages
                          .First();

                // Update
                bag.CODE_IATA = "TREZA";
                bag.SSUR      = "AZE";
                db.SaveChanges();

                // Delete
                db.Remove(bag);


                // Read
                var voll = db.Vols
                           .First();

                Console.WriteLine("---------------");
                Console.WriteLine(voll.Bagages.Count);



                db.SaveChanges();
            }
            Console.WriteLine("Hello World!");
        }
コード例 #6
0
 public int SaveChanges()
 {
     return(dbContext.SaveChanges());
 }
 public void Create(Aircrafts item)
 {
     dataSource.AircraftsList.Add(item);
     dataSource.SaveChanges();
 }
コード例 #8
0
 public void Create(Aviator aviator)
 {
     data.Aviators.Add(aviator);
     data.SaveChanges();
 }
コード例 #9
0
        public static void Initialize(AirportContext context)
        {
            var Airplanes     = GetAirplanes();
            var AirplaneTypes = GetAirplaneTypes();
            var Pilots        = GetPilots();
            var Hostesses     = GetHostesses();
            var Crews         = GetGrews();
            var Tickets       = GetTickets();
            var Flights       = GetFlights();
            var Departures    = GetDepartures();

            context.Database.EnsureCreated();


            if (!context.Airplanes.Any())
            {
                foreach (var plane in Airplanes)
                {
                    context.Airplanes.Add(plane);
                }
            }

            if (!context.AirplaneTypes.Any())
            {
                foreach (var item in AirplaneTypes)
                {
                    context.AirplaneTypes.Add(item);
                }
            }

            if (!context.Crews.Any())
            {
                foreach (var item in Crews)
                {
                    context.Crews.Add(item);
                }
            }


            if (!context.Pilots.Any())
            {
                foreach (var item in Pilots)
                {
                    context.Pilots.Add(item);
                }
            }


            if (!context.Hostesses.Any())
            {
                foreach (var item in Hostesses)
                {
                    context.Hostesses.Add(item);
                }
            }


            if (!context.Tickets.Any())
            {
                foreach (var item in Tickets)
                {
                    context.Tickets.Add(item);
                }
            }


            if (!context.Flights.Any())
            {
                foreach (var item in Flights)
                {
                    context.Flights.Add(item);
                }
            }


            if (!context.Departures.Any())
            {
                foreach (var item in Departures)
                {
                    context.Departures.Add(item);
                }
            }

            context.SaveChanges();
        }
コード例 #10
0
        public static void Initialize(AirportContext airportDbContext)
        {
            airportDbContext.Database.EnsureCreated();

            var stewardesses = new List <Stewardesses>
            {
                new Stewardesses {
                    Sid = 1, Name = "Alica", Surname = "Alison", DateOfBirth = new DateTime(1990, 09, 12, 12, 13, 14)
                },
                new Stewardesses {
                    Sid = 2, Name = "Rosa", Surname = "Rosason", DateOfBirth = new DateTime(1990, 09, 13, 12, 13, 14)
                },
                new Stewardesses {
                    Sid = 3, Name = "Eva", Surname = "Evason", DateOfBirth = new DateTime(1990, 09, 12, 14, 13, 14)
                },
                new Stewardesses {
                    Sid = 4, Name = "Jenn", Surname = "Jennson", DateOfBirth = new DateTime(1990, 09, 15, 12, 13, 14)
                },
                new Stewardesses {
                    Sid = 5, Name = "Hermy", Surname = "Hermyson", DateOfBirth = new DateTime(1990, 09, 16, 12, 13, 14)
                },
                new Stewardesses {
                    Sid = 6, Name = "Alica", Surname = "Evason", DateOfBirth = new DateTime(1990, 09, 12, 17, 13, 14)
                }
            };


            if (!airportDbContext.StewardessesList.Any())
            {
                foreach (var s in stewardesses)
                {
                    airportDbContext.StewardessesList.Add(s);
                }
            }



            var pilots = new Pilots[]
            {
                new Pilots {
                    Pid = 1, Name = "Henry", Surname = "Henryson", DateOfBirth = new DateTime(1980, 09, 12, 12, 13, 14), Experience = 10
                },
                new Pilots {
                    Pid = 2, Name = "Andrew", Surname = "Andrewson", DateOfBirth = new DateTime(1980, 09, 13, 12, 13, 14), Experience = 11
                },
                new Pilots {
                    Pid = 3, Name = "Jonh", Surname = "Jonhson", DateOfBirth = new DateTime(1980, 09, 12, 14, 13, 14), Experience = 12
                },
                new Pilots {
                    Pid = 4, Name = "Harry", Surname = "Harryson", DateOfBirth = new DateTime(1980, 09, 15, 12, 13, 14), Experience = 13
                }
            };

            if (!airportDbContext.PilotsList.Any())
            {
                foreach (var s in pilots)
                {
                    airportDbContext.PilotsList.Add(s);
                }
            }

            var crews = new Crews[]
            {
                new Crews {
                    Cid = 1, Pilot = pilots[0], StewardessList = new List <Stewardesses> {
                        stewardesses[0], stewardesses[1]
                    }
                },
                new Crews {
                    Cid = 2, Pilot = pilots[1], StewardessList = new List <Stewardesses> {
                        stewardesses[2]
                    }
                },
                new Crews {
                    Cid = 3, Pilot = pilots[2], StewardessList = new List <Stewardesses> {
                        stewardesses[3], stewardesses[4]
                    }
                },
                new Crews {
                    Cid = 4, Pilot = pilots[3], StewardessList = new List <Stewardesses> {
                        stewardesses[5]
                    }
                },
            };

            if (!airportDbContext.CrewsList.Any())
            {
                foreach (var s in crews)
                {
                    airportDbContext.CrewsList.Add(s);
                }
            }


            var aircraftsModels = new List <AircraftsModels>
            {
                new AircraftsModels {
                    AMid = 1, ModelName = "Antonov-111", AircraftTonnage = 1000, PlacesCount = 500
                },
                new AircraftsModels {
                    AMid = 2, ModelName = "Ruslanov-222", AircraftTonnage = 1200, PlacesCount = 600
                },
                new AircraftsModels {
                    AMid = 3, ModelName = "Karasov-333", AircraftTonnage = 1400, PlacesCount = 700
                },
                new AircraftsModels {
                    AMid = 4, ModelName = "Menesov-444", AircraftTonnage = 1600, PlacesCount = 800
                }
            };

            if (!airportDbContext.AircraftsModelsList.Any())
            {
                foreach (var s in aircraftsModels)
                {
                    airportDbContext.AircraftsModelsList.Add(s);
                }
            }


            var aircrafts = new List <Aircrafts>
            {
                new Aircrafts {
                    Aid = 1, AircraftName = "Tyt101", AircraftBuildDate = new DateTime(2000, 10, 12, 15, 18, 10), AircraftsModels = aircraftsModels[0], AircraftExpluatationSpan = new TimeSpan(500, 0, 0).Ticks
                },
                new Aircrafts {
                    Aid = 2, AircraftName = "Ty202", AircraftBuildDate = new DateTime(2001, 10, 12, 15, 18, 10), AircraftsModels = aircraftsModels[1], AircraftExpluatationSpan = new TimeSpan(600, 0, 0).Ticks
                },
                new Aircrafts {
                    Aid = 3, AircraftName = "Ty303", AircraftBuildDate = new DateTime(1999, 10, 12, 15, 18, 10), AircraftsModels = aircraftsModels[2], AircraftExpluatationSpan = new TimeSpan(700, 0, 0).Ticks
                },
                new Aircrafts {
                    Aid = 4, AircraftName = "Ty404", AircraftBuildDate = new DateTime(1998, 10, 12, 15, 18, 10), AircraftsModels = aircraftsModels[3], AircraftExpluatationSpan = new TimeSpan(800, 0, 0).Ticks
                }
            };

            if (!airportDbContext.AircraftsList.Any())
            {
                foreach (var s in aircrafts)
                {
                    airportDbContext.AircraftsList.Add(s);
                }
            }

            var tickets = new Tickets[] {
                new Tickets {
                    Tid = 1, Price = 100
                },
                new Tickets {
                    Tid = 2, Price = 100
                },
                new Tickets {
                    Tid = 3, Price = 101
                },
                new Tickets {
                    Tid = 4, Price = 10
                },
                new Tickets {
                    Tid = 5, Price = 102
                },
                new Tickets {
                    Tid = 6, Price = 10
                },
                new Tickets {
                    Tid = 7, Price = 103
                },
                new Tickets {
                    Tid = 8, Price = 103
                }
            };


            if (!airportDbContext.TicketsList.Any())
            {
                foreach (var t in tickets)
                {
                    airportDbContext.TicketsList.Add(t);
                }
            }


            var flights = new List <Flights> {
                new Flights {
                    Fid = 1, PointOfDepartures = "kiev/zhulyany", TimeOfDeparture = new DateTime(2018, 10, 12, 15, 18, 10), PointOfDestination = "london/hitrow", TimeOfArrival = new DateTime(2018, 10, 13, 15, 18, 10), Tickets = new List <Tickets> {
                        tickets[0], tickets[1]
                    }
                },
                new Flights {
                    Fid = 2, PointOfDepartures = "kiev/zhulyany", TimeOfDeparture = new DateTime(2018, 10, 13, 16, 19, 10), PointOfDestination = "tokio/haneda", TimeOfArrival = new DateTime(2018, 10, 14, 15, 18, 10), Tickets = new List <Tickets> {
                        tickets[2], tickets[3]
                    }
                },
                new Flights {
                    Fid = 3, PointOfDepartures = "kiev/zhulyany", TimeOfDeparture = new DateTime(2018, 10, 14, 17, 20, 10), PointOfDestination = "hong-kong/hka", TimeOfArrival = new DateTime(2018, 10, 15, 15, 18, 10), Tickets = new List <Tickets> {
                        tickets[4], tickets[5]
                    }
                },
                new Flights {
                    Fid = 4, PointOfDepartures = "kiev/zhulyany", TimeOfDeparture = new DateTime(2018, 10, 15, 18, 21, 10), PointOfDestination = "new-york/nwa", TimeOfArrival = new DateTime(2018, 10, 16, 15, 18, 10), Tickets = new List <Tickets> {
                        tickets[6], tickets[7]
                    }
                }
            };


            if (!airportDbContext.FlightsList.Any())
            {
                foreach (var f in flights)
                {
                    airportDbContext.FlightsList.Add(f);
                }
            }



            var departures = new List <Departures> {
                new Departures {
                    Did = 1, Flight = flights[0], DepartureDate = new DateTime(2018, 10, 12, 15, 18, 10), Crew = crews[0], Aircraft = aircrafts[0]
                },
                new Departures {
                    Did = 2, Flight = flights[1], DepartureDate = new DateTime(2018, 10, 13, 15, 18, 10), Crew = crews[1], Aircraft = aircrafts[0]
                },
                new Departures {
                    Did = 3, Flight = flights[2], DepartureDate = new DateTime(2018, 10, 14, 15, 18, 10), Crew = crews[2], Aircraft = aircrafts[0]
                },
                new Departures {
                    Did = 4, Flight = flights[3], DepartureDate = new DateTime(2018, 10, 15, 15, 18, 10), Crew = crews[3], Aircraft = aircrafts[0]
                }
            };


            if (!airportDbContext.DeparturesList.Any())
            {
                foreach (var f in departures)
                {
                    airportDbContext.DeparturesList.Add(f);
                }
            }

            airportDbContext.SaveChanges();
        }
コード例 #11
0
 public void Create(Plane plane)
 {
     data.Planes.Add(plane);
     data.SaveChanges();
 }
コード例 #12
0
 public void Create(Flight flight)
 {
     data.Flights.Add(flight);
     data.SaveChanges();
 }
コード例 #13
0
 public void SaveChanges()
 {
     _airportContext.SaveChanges();
 }
コード例 #14
0
 public virtual void Create(TEntity entity)
 {
     DbContext.SetOf <TEntity>().Add(entity);
     DbContext.SaveChanges();
 }
コード例 #15
0
 public void Create(TypePlane typePlane)
 {
     data.TypesPlane.Add(typePlane);
     data.SaveChanges();
 }
コード例 #16
0
 public async Task <int> AddAirport(AirportRaw model)
 {
     _context.Airports.Add(model);
     return(_context.SaveChanges());
 }
コード例 #17
0
 public void Commit()
 {
     context.SaveChanges();
 }
コード例 #18
0
ファイル: UnitOfWork.cs プロジェクト: KGerasymiva/Homework4
 public int SaveChages()
 {
     return(context.SaveChanges());
 }
コード例 #19
0
        public static void EnsureDatabaseSeeded(this AirportContext context)
        {
            if (!context.Pilots.Any())
            {
                context.AddRange(new Pilot[]
                {
                    new Pilot
                    {
                        FirstName  = "Petro",
                        LastName   = "Chernov",
                        Birthdate  = new DateTime(1990, 2, 5),
                        Experience = 5
                    },
                    new Pilot
                    {
                        FirstName  = "Alex",
                        LastName   = "Yaschenko",
                        Birthdate  = new DateTime(1983, 6, 28),
                        Experience = 3
                    },
                    new Pilot
                    {
                        FirstName  = "Ivan",
                        LastName   = "Golub",
                        Birthdate  = new DateTime(1993, 12, 31),
                        Experience = 1
                    },
                    new Pilot
                    {
                        FirstName  = "Anrew",
                        LastName   = "Novikov",
                        Birthdate  = new DateTime(1975, 8, 14),
                        Experience = 8
                    }
                });
                context.SaveChanges();
            }


            if (!context.Stewardesses.Any())
            {
                context.AddRange(new Stewardesse[]
                {
                    new Stewardesse {
                        FirstName = "Natalia",
                        LastName  = "Korobko",
                        Birthdate = new DateTime(1986, 5, 21)
                    },
                    new Stewardesse
                    {
                        FirstName = "Olha",
                        LastName  = "Bilyk",
                        Birthdate = new DateTime(1979, 6, 27)
                    },
                    new Stewardesse
                    {
                        FirstName = "Nina",
                        LastName  = "Ivanova",
                        Birthdate = new DateTime(1995, 9, 17)
                    },
                    new Stewardesse
                    {
                        FirstName = "Viktoria",
                        LastName  = "Petrova",
                        Birthdate = new DateTime(1997, 7, 17)
                    },
                    new Stewardesse
                    {
                        FirstName = "Daria",
                        LastName  = "Kolomiets",
                        Birthdate = new DateTime(1991, 3, 13)
                    },
                    new Stewardesse
                    {
                        FirstName = "Maria",
                        LastName  = "Bondarenko",
                        Birthdate = new DateTime(1994, 10, 5)
                    },
                    new Stewardesse
                    {
                        FirstName = "Anastasia",
                        LastName  = "Golovko",
                        Birthdate = new DateTime(1989, 12, 25)
                    }
                });
                context.SaveChanges();
            }

            if (!context.Crews.Any())
            {
                context.AddRange(new Crew[]
                {
                    new Crew
                    {
                        Pilot = new Pilot
                        {
                            Birthdate  = new DateTime(1987, 3, 1),
                            Experience = 6,
                            FirstName  = "Sasha",
                            LastName   = "Saharov"
                        },
                        Stewardesses = new List <Stewardesse> {
                            new Stewardesse
                            {
                                Birthdate = new DateTime(1989, 1, 2),
                                FirstName = "Samira",
                                LastName  = "Elbrus"
                            },
                            new Stewardesse
                            {
                                Birthdate = new DateTime(1989, 1, 3),
                                FirstName = "Elvira",
                                LastName  = "Elbrus"
                            }
                        }
                    },
                    new Crew
                    {
                        Pilot = new Pilot
                        {
                            Birthdate  = new DateTime(1991, 12, 2),
                            FirstName  = "Maxim",
                            LastName   = "Suvorov",
                            Experience = 15
                        },
                        Stewardesses = new List <Stewardesse> {
                            new Stewardesse
                            {
                                Birthdate = new DateTime(1989, 1, 5),
                                FirstName = "Valeriya",
                                LastName  = "Solomko"
                            }
                        }
                    },
                    new Crew
                    {
                        Pilot = new Pilot
                        {
                            Birthdate  = new DateTime(1991, 10, 2),
                            FirstName  = "Vadim",
                            LastName   = "Melnik",
                            Experience = 15
                        },
                        Stewardesses = new List <Stewardesse> {
                            new Stewardesse
                            {
                                Birthdate = new DateTime(1979, 2, 5),
                                FirstName = "Irina",
                                LastName  = "Natamina"
                            }
                        }
                    }
                });
                context.SaveChanges();
            }

            if (!context.AirplaneTypes.Any())
            {
                context.AddRange(new AirplaneType[]
                {
                    new AirplaneType
                    {
                        AirplaneModel    = "Typolev Ty-134",
                        CarryingCapacity = 47000,
                        SeatsCount       = 96
                    },
                    new AirplaneType
                    {
                        AirplaneModel    = "Typolev Ty-154",
                        CarryingCapacity = 52000,
                        SeatsCount       = 158
                    },
                    new AirplaneType
                    {
                        AirplaneModel    = "Sukhoi SuperJet-100",
                        CarryingCapacity = 45900,
                        SeatsCount       = 86
                    },
                    new AirplaneType
                    {
                        AirplaneModel    = "Illyushin IL-62",
                        CarryingCapacity = 280300,
                        SeatsCount       = 198
                    },
                    new AirplaneType
                    {
                        AirplaneModel    = "Airbus A310",
                        CarryingCapacity = 164000,
                        SeatsCount       = 183
                    }
                });
                context.SaveChanges();
            }

            if (!context.Airplanes.Any())
            {
                context.Airplanes.AddRange(new Airplane[]
                {
                    new Airplane
                    {
                        Name = "A. Dayneka",
                        Type = new AirplaneType
                        {
                            AirplaneModel    = "NYA-226",
                            CarryingCapacity = 15000,
                            SeatsCount       = 987
                        },
                        ExploitationTerm = TimeSpan.FromTicks(100000000),
                        ReleaseDate      = new DateTime(1985, 5, 21)
                    },
                    new Airplane
                    {
                        Name = "Manchester United",
                        Type = new AirplaneType
                        {
                            AirplaneModel    = "MNA-566",
                            CarryingCapacity = 19000,
                            SeatsCount       = 876
                        },
                        ExploitationTerm = TimeSpan.FromTicks(5000000),
                        ReleaseDate      = new DateTime(1990, 7, 12)
                    },
                    new Airplane
                    {
                        Name = "Retro",
                        Type = new AirplaneType
                        {
                            AirplaneModel    = "OKA-221",
                            CarryingCapacity = 30000,
                            SeatsCount       = 658
                        },
                        ExploitationTerm = TimeSpan.FromTicks(8000000),
                        ReleaseDate      = new DateTime(1980, 12, 11)
                    }
                });
                context.SaveChanges();
            }

            if (!context.Flights.Any())
            {
                context.Flights.AddRange(new Flight[]
                {
                    new Flight
                    {
                        Number           = "DY-2891",
                        ArrivalTime      = new DateTime(2018, 07, 12, 12, 24, 0),
                        DeparturePoint   = "Borispol, Ukraine",
                        DestinationPoint = "New York, USA",
                        Tickets          = new List <Ticket>
                        {
                            new Ticket
                            {
                                FlightNumber = "DY-2891",
                                Price        = 300
                            },
                            new Ticket
                            {
                                FlightNumber = "DY-2891",
                                Price        = 600
                            }
                        }
                    },
                    new Flight
                    {
                        Number           = "AC-3948",
                        ArrivalTime      = new DateTime(2018, 08, 15, 14, 12, 0),
                        DeparturePoint   = "Borispol, Ukraine",
                        DestinationPoint = "Moscow, Russia",
                        Tickets          = new List <Ticket>
                        {
                            new Ticket
                            {
                                FlightNumber = "AC-3948",
                                Price        = 400
                            },
                            new Ticket
                            {
                                FlightNumber = "AC-3948",
                                Price        = 700
                            }
                        }
                    },
                    new Flight
                    {
                        Number           = "KO-8712",
                        ArrivalTime      = new DateTime(2018, 10, 5, 20, 21, 0),
                        DeparturePoint   = "Borispol, Ukraine",
                        DestinationPoint = "Katowice, Poland",
                        Tickets          = new List <Ticket>
                        {
                            new Ticket
                            {
                                FlightNumber = "KO-8712",
                                Price        = 1300
                            },
                            new Ticket
                            {
                                FlightNumber = "KO-8712",
                                Price        = 6000
                            }
                        }
                    }
                });
                context.SaveChanges();
            }

            if (!context.Tickets.Any())
            {
                context.Tickets.AddRange(new Ticket[]
                {
                    new Ticket
                    {
                        FlightNumber = "AC-3948",
                        Price        = 200m
                    },
                    new Ticket
                    {
                        FlightNumber = "KO-8712",
                        Price        = 400m
                    },
                    new Ticket
                    {
                        FlightNumber = "DY-2891",
                        Price        = 600m
                    },
                    new Ticket
                    {
                        FlightNumber = "KO-8712",
                        Price        = 100m
                    },
                    new Ticket
                    {
                        FlightNumber = "DY-2891",
                        Price        = 150m
                    },
                    new Ticket
                    {
                        FlightNumber = "KO-8712",
                        Price        = 450m
                    }
                });
                context.SaveChanges();
            }

            if (!context.Departures.Any())
            {
                context.AddRange(new Departure[]
                {
                    new Departure
                    {
                        FlightNumber = "AM-2325",
                        Airplane     = new Airplane
                        {
                            ExploitationTerm = TimeSpan.FromTicks(7000000),
                            Name             = "FirstClassPlane",
                            Type             = new AirplaneType
                            {
                                SeatsCount       = 879,
                                AirplaneModel    = "AR-228",
                                CarryingCapacity = 25000
                            }
                        },
                        Crew = new Crew
                        {
                            Stewardesses = new List <Stewardesse>
                            {
                                new Stewardesse
                                {
                                    Birthdate = new DateTime(1987, 12, 15),
                                    FirstName = "Larisa",
                                    LastName  = "Bolinskaya"
                                }
                            },
                            Pilot = new Pilot
                            {
                                Birthdate  = new DateTime(1978, 5, 21),
                                FirstName  = "Bohdan",
                                LastName   = "Klavimak",
                                Experience = 21
                            }
                        },
                        DepartureTime = new DateTime(2018, 10, 21, 20, 22, 0)
                    }
                });
                context.SaveChanges();
            }
        }
コード例 #20
0
 public void Create(Ticket ticket)
 {
     data.Tickets.Add(ticket);
     data.SaveChanges();
 }
コード例 #21
0
 public void Save()
 {
     context.SaveChanges();
 }
コード例 #22
0
 public void SaveChanges()
 {
     _ctx.SaveChanges();
 }
コード例 #23
0
ファイル: DataSource.cs プロジェクト: FelixCukerman/Entity
        public DataSource(AirportContext airportContext)
        {
            airportContext.Database.EnsureCreated();

            if (!(airportContext.Aviators.Any(p => p.Name == "Alex" && p.Surname == "Harper" && p.Experience == 3 && p.DateOfBirthday == DateTime.MinValue)))
            {
                List <Aviator> aviators = new List <Aviator>
                {
                    new Aviator {
                        Name = "Alex", Surname = "Harper", Experience = 3, DateOfBirthday = DateTime.MinValue
                    },
                    new Aviator {
                        Name = "Qwer", Surname = "Tiger", Experience = 2, DateOfBirthday = DateTime.Now
                    },
                    new Aviator {
                        Name = "Chery", Surname = "Bim", Experience = 1, DateOfBirthday = DateTime.MaxValue
                    }
                };
                airportContext.Aviators.AddRange(aviators);

                List <Crew> crews = new List <Crew>
                {
                    new Crew {
                        aviator = new Aviator(), stewardesses = new List <Stewardess>()
                    },
                    new Crew {
                        aviator = new Aviator(), stewardesses = new List <Stewardess>()
                    },
                    new Crew {
                        aviator = new Aviator(), stewardesses = new List <Stewardess>()
                    }
                };
                airportContext.Crews.AddRange(crews);

                List <Departure> departures = new List <Departure>
                {
                    new Departure {
                        FlightNumber = 111, PlaneId = 100, CrewId = 1
                    },
                    new Departure {
                        FlightNumber = 222, PlaneId = 200, CrewId = 2
                    },
                    new Departure {
                        FlightNumber = 333, PlaneId = 300, CrewId = 3
                    }
                };
                airportContext.Departures.AddRange(departures);

                List <Flight> flights = new List <Flight>
                {
                    new Flight {
                        Destination = "nulL", TicketId = 1
                    },
                    new Flight {
                        Destination = "Null", TicketId = 2
                    },
                    new Flight {
                        Destination = "nUll", TicketId = 3
                    }
                };
                airportContext.Flights.AddRange(flights);

                List <Plane> planes = new List <Plane>
                {
                    new Plane {
                        Name = "qwe", TimeSpan = 3, Type = "A"
                    },
                    new Plane {
                        Name = "rty", TimeSpan = 4, Type = "B"
                    },
                    new Plane {
                        Name = "zxc", TimeSpan = 5, Type = "C"
                    }
                };
                airportContext.Planes.AddRange(planes);

                List <Stewardess> stewardesses = new List <Stewardess>
                {
                    new Stewardess {
                        Name = "Anna", Surname = "Kasparova"
                    },
                    new Stewardess {
                        Name = "Zany", Surname = "Jimova"
                    },
                    new Stewardess {
                        Name = "Sara", Surname = "Binomy"
                    }
                };
                airportContext.Stewardesses.AddRange(stewardesses);

                List <Ticket> tickets = new List <Ticket>
                {
                    new Ticket {
                        Price = 1000
                    },
                    new Ticket {
                        Price = 2000
                    },
                    new Ticket {
                        Price = 3000
                    }
                };
                airportContext.Tickets.AddRange(tickets);

                List <TypePlane> typesPlane = new List <TypePlane>
                {
                    new TypePlane {
                        CarryingCapacity = 1000, CountOfSeats = 60
                    },
                    new TypePlane {
                        CarryingCapacity = 1200, CountOfSeats = 80
                    },
                    new TypePlane {
                        CarryingCapacity = 1500, CountOfSeats = 100
                    }
                };
                airportContext.TypesPlane.AddRange(typesPlane);

                airportContext.SaveChanges();
            }
        }
コード例 #24
0
 public void Create(Crew crew)
 {
     data.Crews.Add(crew);
     data.SaveChanges();
 }