static FlightManager()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();
                 
                if (!ctx.Flights.Any()) {

                    var f1 = new Flight { From = "Graz", To = "Hamburg", Date = DateTime.Now };
                    var f2 = new Flight { From = "Vienna", To = "London",  Date = DateTime.Now.AddHours(1) };
                    var f3 = new Flight { From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(2) };
                    var f4 = new Flight { From = "Hamburg", To = "Graz", Date = DateTime.Now.AddHours(3) };
                    var f5 = new Flight { From = "Vienna", To = "London", Date = DateTime.Now.AddHours(4) };
                    var f6 = new Flight { From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(5) };
                    var f7 = new Flight { From = "Vienna", To = "London",  Date = DateTime.Now.AddHours(6) };

                    var b1 = new Booking { PassengerId = 4711, Price = 300 };
                    f1.Bookings.Add(b1);

                    ctx.Flights.AddRange(f1, f2, f3, f4, f5, f6, f7);
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 2
0
 public List <Flight> FindByRoute(string from, string to)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return(ctx.Flights.Where(f => f.From == from && f.To == to).ToList());
     }
 }
 public void Create(Flight flight) {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Add(flight);
         ctx.SaveChanges();
     }
 }
 public List <Flug> FindByRoute(string from, string to)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return(ctx.Fluege.Where(f => f.Abflugort == from && f.Zielort == to).ToList());
     }
 }
Esempio n. 5
0
 public void Create(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Add(flight);
         ctx.SaveChanges();
     }
 }
 public void Update(Flug flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Fluege.Update(flight);
         ctx.SaveChanges();
     }
 }
Esempio n. 7
0
 public void Delete(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Remove(flight);
         ctx.SaveChanges();
     }
 }
 public void Delete(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Remove(flight);
         ctx.SaveChanges();
     }
 }
 public void Update(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Update(flight);
         //ctx.Entry(flight).Property("PlaneType").CurrentValue = "Boeing";
         ctx.SaveChanges();
     }
 }
 public Flight FindById(int id) {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return ctx.Flights
                     .Include(f => f.Bookings)
                     .Where(f => f.Id == id)
                     .FirstOrDefault();
     }
 }
Esempio n. 11
0
 public void Update(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Update(flight);
         //ctx.Entry(flight).Property("PlaneType").CurrentValue = "Boeing";
         ctx.SaveChanges();
     }
 }
 public Flug FindById(int id)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return(ctx.Fluege
                .Include(f => f.Buchungen)
                .Where(f => f.Id == id)
                .FirstOrDefault());
     }
 }
Esempio n. 13
0
 public void Merge(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.ChangeTracker.TrackGraph(flight, (node) => {
             node.Entry.State = EntityState.Modified;
         });
         ctx.SaveChanges();
     }
 }
Esempio n. 14
0
 public Flight FindById(int id)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return(ctx.Flights
                .Include(f => f.Bookings)
                .Where(f => f.Id == id)
                .FirstOrDefault());
     }
 }
Esempio n. 15
0
        public void ShowShadowState()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                // ctx.LogToConsole();
                var flights = ctx.Flights.Where(f => Check(f)).ToList();

                foreach (var f in flights)
                {
                    Console.WriteLine(f.Id);
                    //var planeType = ctx.Entry(f).Property("PlaneType").CurrentValue;
                    //Console.WriteLine(planeType);
                }
            }
        }
        static FlugManager()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();

                if (!ctx.Fluege.Any())
                {
                    var f1 = new Flug {
                        Abflugort = "Graz", Zielort = "Hamburg", Datum = DateTime.Now
                    };
                    var f2 = new Flug {
                        Abflugort = "Wien", Zielort = "London", Datum = DateTime.Now.AddHours(1)
                    };
                    var f3 = new Flug {
                        Abflugort = "Graz", Zielort = "Hamburg", Datum = DateTime.Now.AddHours(2)
                    };
                    var f4 = new Flug {
                        Abflugort = "Hamburg", Zielort = "Graz", Datum = DateTime.Now.AddHours(3)
                    };
                    var f5 = new Flug {
                        Abflugort = "Hamburg", Zielort = "Wien", Datum = DateTime.Now.AddHours(4)
                    };
                    var f6 = new Flug {
                        Abflugort = "Graz", Zielort = "Hamburg", Datum = DateTime.Now.AddHours(5)
                    };
                    var f7 = new Flug {
                        Abflugort = "Wien", Zielort = "London", Datum = DateTime.Now.AddHours(6)
                    };

                    var b1 = new Buchung {
                        PassagierId = 4711, Preis = 300
                    };
                    f1.Buchungen.Add(b1);

                    ctx.Fluege.AddRange(f1, f2, f3, f4, f5, f6, f7);
                    ctx.SaveChanges();
                }
            }

            using (FlugDbContext ctx = new FlugDbContext())
            {
                var all = ctx.Fluege.ToList();
                Debug.WriteLine(all.Count);
            }
        }
Esempio n. 17
0
        static FlightManager()
        {
            using (FlugDbContext ctx = new FlugDbContext())
            {
                ctx.Database.EnsureDeleted();
                ctx.Database.EnsureCreated();

                if (!ctx.Flights.Any())
                {
                    var f1 = new Flight {
                        From = "Graz", To = "Hamburg", Date = DateTime.Now
                    };
                    var f2 = new Flight {
                        From = "Vienna", To = "London", Date = DateTime.Now.AddHours(1)
                    };
                    var f3 = new Flight {
                        From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(2)
                    };
                    var f4 = new Flight {
                        From = "Hamburg", To = "Graz", Date = DateTime.Now.AddHours(3)
                    };
                    var f5 = new Flight {
                        From = "Vienna", To = "London", Date = DateTime.Now.AddHours(4)
                    };
                    var f6 = new Flight {
                        From = "Graz", To = "Hamburg", Date = DateTime.Now.AddHours(5)
                    };
                    var f7 = new Flight {
                        From = "Vienna", To = "London", Date = DateTime.Now.AddHours(6)
                    };

                    var b1 = new Booking {
                        PassengerId = 4711, Price = 300
                    };
                    f1.Bookings.Add(b1);

                    ctx.Flights.AddRange(f1, f2, f3, f4, f5, f6, f7);
                    ctx.SaveChanges();
                }
            }
        }
 public List<Flight> FindByRoute(string from, string to) {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return ctx.Flights.Where(f => f.From == from && f.To == to).ToList();
     }
 }
 public List <Flug> FindAll()
 {
     using (FlugDbContext ctx = new FlugDbContext()) {
         return(ctx.Fluege.ToList());
     }
 }
        public void Merge(Flight flight) {

            using (FlugDbContext ctx = new FlugDbContext())
            {
                ctx.ChangeTracker.TrackGraph(flight, (node) => {
                    node.Entry.State = EntityState.Modified;
                });
                ctx.SaveChanges();
            }
        }
 public List<Flight> FindAll() {
     using (FlugDbContext ctx = new FlugDbContext()) {
         return ctx.Flights.ToList();
     }
 }
        public void ShowShadowState() {

            using (FlugDbContext ctx = new FlugDbContext())
            {
                // ctx.LogToConsole();
                var flights = ctx.Flights.Where(f => Check(f)).ToList();

                foreach(var f in flights) {
                    Console.WriteLine(f.Id);
                    //var planeType = ctx.Entry(f).Property("PlaneType").CurrentValue;
                    //Console.WriteLine(planeType);
                }

            }
        }