Ejemplo n.º 1
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();
                }
            }
        }
Ejemplo 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());
     }
 }
Ejemplo n.º 3
0
 public void Create(Flight flight) {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Add(flight);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 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());
     }
 }
Ejemplo n.º 5
0
 public void Create(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Add(flight);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void Update(Flug flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Fluege.Update(flight);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public void Delete(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Remove(flight);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public void Delete(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Remove(flight);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void Update(Flight flight)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         ctx.Flights.Update(flight);
         //ctx.Entry(flight).Property("PlaneType").CurrentValue = "Boeing";
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public Flight FindById(int id) {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return ctx.Flights
                     .Include(f => f.Bookings)
                     .Where(f => f.Id == id)
                     .FirstOrDefault();
     }
 }
Ejemplo 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();
     }
 }
Ejemplo n.º 12
0
 public Flug FindById(int id)
 {
     using (FlugDbContext ctx = new FlugDbContext())
     {
         return(ctx.Fluege
                .Include(f => f.Buchungen)
                .Where(f => f.Id == id)
                .FirstOrDefault());
     }
 }
Ejemplo 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();
     }
 }
Ejemplo 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());
     }
 }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 16
0
        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);
            }
        }
Ejemplo 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();
                }
            }
        }
Ejemplo n.º 18
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();
     }
 }
Ejemplo n.º 19
0
 public List <Flug> FindAll()
 {
     using (FlugDbContext ctx = new FlugDbContext()) {
         return(ctx.Fluege.ToList());
     }
 }
Ejemplo n.º 20
0
        public void Merge(Flight flight) {

            using (FlugDbContext ctx = new FlugDbContext())
            {
                ctx.ChangeTracker.TrackGraph(flight, (node) => {
                    node.Entry.State = EntityState.Modified;
                });
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 21
0
 public List<Flight> FindAll() {
     using (FlugDbContext ctx = new FlugDbContext()) {
         return ctx.Flights.ToList();
     }
 }
Ejemplo n.º 22
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);
                }

            }
        }