static void Main(string[] args) { Console.WriteLine("Hello World!"); using (MyAirportContext context = new MyAirportContext()) { Bagage b1 = new Bagage { CodeIATA = "098765432" }; Bagage b2 = new Bagage { CodeIATA = "098723543", Poids = 4 }; Vol v1 = new Vol { Cie = "LH", DateVol = Convert.ToDateTime("12/12/2020 16:12"), Ligne = "34567", Parking = "7UY", Bagages = new System.Collections.Generic.List <Bagage> { b1, b2 } }; Vol v2 = new Vol { Cie = "SQ", DateVol = Convert.ToDateTime("12/12/2020 21:21"), Ligne = "222", Parking = "Z54" }; context.Add(v1); context.Add(v2); context.SaveChanges(); } }
static void Main(string[] args) { System.Console.WriteLine("MyAirport project bonjour!!"); var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); //optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Airport;Integrated Security=True"); optionsBuilder.UseLoggerFactory(MyAirportLoggerFactory); using (var db = new MyAirportContext(optionsBuilder.Options)) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { CIE = @"LH", DES = @"BKK", DHC = Convert.ToDateTime("14/01/2020 16:45"), IMM = "RZ62", LIG = "1232", PKG = "R52", PAX = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { CIE = "SK", DES = "CDG", DHC = Convert.ToDateTime("14/01/2020 18:20"), IMM = "TG43", LIG = "333", PKG = "R51", PAX = 423 }; db.Add(v2); db.SaveChanges(); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { //VolID = v2.VolId, Classe = "Y", CodeIata = "012387364501", DateCreation = Convert.ToDateTime("14/01/2020 12:52"), Destination = "BEG" }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.CIE); foreach (var v in vol) { Console.WriteLine($"Le vol {v.CIE}{v.LIG} N° {v.VolId} a destination de {v.DES} part à {v.DHC} heure"); } Console.ReadLine(); // Update //Console.WriteLine($"Le bagage {b1.BagageID} est modifié pour être rattaché au vol {v1.VolId} => {v1.CIE}{v1.LIG}"); Console.WriteLine($"Le bagage {b1.BagageID} est modifié pour être rattaché au vol {v2.VolId} => {v2.CIE}{v2.LIG}"); b1.VolID = v2.VolId; db.SaveChanges(); Console.ReadLine(); // Delete vol et bagages du vol Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.CIE}{v1.LIG}"); db.Remove(v1); db.SaveChanges(); Console.ReadLine(); } }
static void Main(string[] args) { var logger = MyAirportContext.loggerFactory.CreateLogger <Program>(); System.Console.WriteLine("MyAirport project bonjour!!"); using (var db = new MyAirportContext()) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { Cie = "LH", Destination = "BKK", Dhc = Convert.ToDateTime("14/01/2020 16:45"), Immatriculation = "RZ62", Lig = "1232", Parking = "R52", NbPassagers = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { Cie = "SK", Destination = "CDG", Dhc = Convert.ToDateTime("14/01/2020 18:20"), Immatriculation = "TG43", Lig = "333", Parking = "R51", NbPassagers = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { Classe = "Y", CodeIata = "012387364501", DateCreation = DateTime.Now, Destination = "BEG", Escale = "Paris", SSUR = "SSUR", Sta = "Sta", Prioritaire = 1 }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); logger.LogInformation("Example log message create"); //Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolId} a destination de {v.Destination} part à {v.Dhc} heure"); } Console.ReadLine(); //Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au "); b1.VolId = v1.VolId; db.SaveChanges(); Console.ReadLine(); //Delete vol et bagages du vol Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.Cie}{v1.Lig}"); db.Remove(v1); db.SaveChanges(); Console.ReadLine(); } }
static void Main(string[] args) { ILogger logger = MyLoggerFactoy.CreateLogger <Program>(); logger.LogInformation("Logger initialized"); var connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>() .UseSqlServer(connectionString) .UseLoggerFactory(MyLoggerFactoy); Console.WriteLine("MyAirport project bonjour!!"); using (var db = new MyAirportContext(optionsBuilder.Options)) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { Cie = "LH", Des = "BKK", Dhc = Convert.ToDateTime("01/14/2020 16:45"), Imm = "RZ62", Lig = "1232", Pkg = "R52", Pax = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { Cie = "SK", Des = "CDG", Dhc = Convert.ToDateTime("01/14/2020 18:20"), Imm = "TG43", Lig = "333", Pkg = "R51", Pax = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { Classe = "Y", CodeIata = "012387364501", DateCreation = Convert.ToDateTime("01/14/2020 12:52"), Destination = "BEG" }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolID} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageID} est modifié pour être rattaché au vol {v1.VolID} => {v1.Cie}{v1.Lig}"); b1.Vol = v1; db.SaveChanges(); v1.Bagages.ToList().ForEach(b => { Console.WriteLine($"Le bagage {b.BagageID} est associé au vol {b.Vol.VolID}."); }); Vol vod = v1; Console.WriteLine("#####################################################"); Console.WriteLine(vod.VolID); vod.Bagages.ToList().ForEach(bag => Console.WriteLine(bag.BagageID)); Console.WriteLine("#####################################################"); Console.ReadLine(); // Delete vol et bagages du vol Console.WriteLine($"Suppression du vol {v1.VolID} => {v1.Cie}{v1.Lig}"); //db.Remove(v1); db.SaveChanges(); Console.ReadLine(); } }
static void Main(string[] args) { var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder.UseLoggerFactory(MyAirportLoggerFactory); optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["MyAirportDatabase"].ConnectionString); System.Console.WriteLine("MyAirport project bonjour!!"); using (var db = new MyAirportContext(optionsBuilder.Options) //var db = new MyAirportContext() ) { //Clear db to begin var bag = db.Bagages; foreach (var b in bag) { db.Remove(b); } var vol = db.Vols; foreach (var v in vol) { db.Remove(v); } db.SaveChanges(); // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { Cie = "LH", Des = "BKK", Dhc = Convert.ToDateTime("14/01/2020 16:45"), Imm = "RZ62", Lig = "1232", Pkg = "R52", Pax = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { Cie = "SK", Des = "CDG", Dhc = Convert.ToDateTime("14/01/2020 18:20"), Imm = "TG43", Lig = "333", Pkg = "R51", Pax = 423 }; db.Add(v2); Console.WriteLine("Creation vol BKK238"); db.Add(new Vol("LH", "1234", Convert.ToDateTime("18/03/2020 16:45")) { Des = "BKK", Imm = "RB22", Pkg = "R52", Pax = 238 } ); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { Classe = "Y", CodeIata = "012387364501", DateCreation = Convert.ToDateTime("14/01/2020 12:52"), Destination = "BEG" }; db.Add(b1); Console.WriteLine("creation du bagage 987654321"); Bagage b2 = new Bagage { Classe = "Y", CodeIata = "987654321", DateCreation = Convert.ToDateTime("12/04/2020 17:18"), Destination = "BEG" }; db.Add(b2); Console.WriteLine("creation du bagage 0123456789"); db.Add(new Bagage("0123456789", Convert.ToDateTime("17/03/2020 14:09")) { Classe = "Y", Destination = "BEG" }); db.SaveChanges(); Console.ReadLine(); // ReadBagages_Vols_VolI Console.WriteLine("Voici la liste des vols disponibles"); var vols = db.Vols .OrderBy(v => v.Cie); foreach (var v in vols) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolId} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v1.VolId} => {v1.Cie}{v1.Lig}"); b1.VolId = v1.VolId; db.SaveChanges(); v1.Bagages.ToList().ForEach(b => Console.WriteLine($"VOLID: {v1.VolId} -> bagage {b.BagageId}")); Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v2.VolId} => {v2.Cie}{v2.Lig}"); b2.VolId = v2.VolId; db.SaveChanges(); v1.Bagages.ToList().ForEach(b => Console.WriteLine($"VOLID: {v2.VolId} -> bagage {b.BagageId}")); Console.ReadLine(); // Delete vol et mise a null du volId dans bagage Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.Cie}{v1.Lig}"); db.Remove(v1); db.SaveChanges(); Console.ReadLine(); // Delete vol et delete des bagages attribués à ce vol Console.WriteLine($"Suppression du vol {v2.VolId} => {v2.Cie}{v2.Lig} induisant suppression du bagage {b2.BagageId} "); var bagages = db.Bagages.Where(b => b.VolId == v2.VolId); foreach (var b in bagages) { db.Remove(b); } db.Remove(v2); db.SaveChanges(); Console.ReadLine(); } }
static void Main() { using (MyAirportContext db = new MyAirportContext()) { // Create // AJOUT DE VOLS Flight f1 = new Flight { CIE = 1, LIG = "AIRFRANCE", JEX = 12, DES = "Londres", DHC = Convert.ToDateTime("24/02/2020 15:01") }; db.Add(f1); Flight f2 = new Flight { CIE = 2, LIG = "AIGLEAZUR", JEX = 13, DES = "Paris", DHC = Convert.ToDateTime("24/02/2020 15:01") }; db.Add(f2); // AJOUT DE BAGAGES Luggage l1 = new Luggage { CODE_IATA = "123456789", DATE_CREATION = Convert.ToDateTime("24/02/2020 15:01"), DESTINATION = "Paris" }; db.Add(l1); db.SaveChanges(); Console.ReadLine(); // Read //var permet de définir une variable dont on connait pas le type Console.WriteLine("Voici la liste des vols diponibles"); var flight = db.Flights //dans le data context (sauvegardée en mémoire mais pas dans la dbs //résultat du select .OrderBy(f => f.CIE); //argument f trier par compagnie foreach (var f in flight) { Console.WriteLine($"Le vol {f.CIE}{f.LIG} N° {f.FLIGHTID} à destination de {f.DES} part à {f.DHC} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {l1.LUGGAGEID} est modifié pour être ..."); l1.FLIGHTID = f1.FLIGHTID; db.SaveChanges(); Console.ReadLine(); // Delete db.Remove(f1); db.SaveChanges(); } }
static void Main(string[] args) { System.Console.WriteLine("Hello!"); DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["MyAirport"].ConnectionString); ///On utilise la factory pour gérer les logs optionsBuilder.UseLoggerFactory(MyLoggerFactory); System.Console.WriteLine("MyAirport project bonjour!!"); DbContextOptions <MyAirportContext> myOptions = (DbContextOptions <MyAirportContext>)optionsBuilder.Options; using (var db = new MyAirportContext(myOptions)) { //// Create //System.Console.WriteLine("Création du vol LH1232"); //Vol v1 = new Vol //{ // CIE = 1, // DES = "BKK", // DHC = Convert.ToDateTime("14/01/2020 16:45"), // IMM = "eer", // LIG = "1232", // PKG = "r", // PAX = 238 //}; //db.Add(v1); //System.Console.WriteLine("Creation vol SQ333"); //Vol v2 = new Vol //{ // CIE = 1, // DES = "CDG", // DHC = Convert.ToDateTime("14/01/2020 18:20"), // IMM = "TG43", // LIG = "333", // PKG = "R51", // PAX = 423 //}; //db.Add(v2); System.Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { CLASSE = "Y", CODE_IATA = "012387364501", DATA_CREATION = Convert.ToDateTime("14/01/2020 12:52"), DESTINATION = "BEG", VolID = 1 }; db.Add(b1); db.SaveChanges(); System.Console.ReadLine(); System.Console.WriteLine("Voici la liste des bagages disponibles"); var bags = db.Bagage .OrderBy(b => b.CODE_IATA); foreach (var b in bags) { System.Console.WriteLine($"Le bagage {b.DATA_CREATION} heure"); } System.Console.ReadLine(); // Read System.Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vol .OrderBy(v => v.CIE); foreach (var v in vol) { System.Console.WriteLine($"Le vol {v.DHC} ");//{v.CIE}{v.LIG} N° {v.VolID} a destination de {v.DES} part à {v.DHC} heure"); } System.Console.ReadLine(); //// Update //System.Console.WriteLine($"Le bagage {b1.BagageID} est modifié pour être rattaché au vol {v1.VolID} => {v1.CIE}{v1.LIG}"); //b1.VolID = v1.VolID; //db.SaveChanges(); //System.Console.ReadLine(); //// Delete vol et bagages du vol //System.Console.WriteLine($"Suppression du vol {v1.VolID} => {v1.CIE}{v1.LIG}"); //db.Remove(v1); //db.SaveChanges(); //System.Console.ReadLine(); } }
static void Main(string[] args) { var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder.UseLoggerFactory(MyAirportLoggerFactory); optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["MyAirportContext"].ConnectionString); System.Console.WriteLine("MyAirport project bonjour!!"); using (var db = new MyAirportContext(optionsBuilder.Options)) //using (var db = new MyAirportContext()) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol("LH", "1232", Convert.ToDateTime("14/01/2020 16:45")) { Des = "BKK", Imm = "RZ62", Pkg = "R52", Pax = 238 }; db.Add(v1); db.SaveChanges(); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol("SK", "333", Convert.ToDateTime("14/01/2020 18:20")) { Des = "CDG", Imm = "TG43", Pkg = "R51", Pax = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage("012387364501", Convert.ToDateTime("14/01/2020 12:52")) { Classe = "Y", Destination = "BEG", }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolId} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v1.VolId} => {v1.Cie}{v1.Lig}"); b1.VolId = v1.VolId; db.SaveChanges(); Console.ReadLine(); Console.WriteLine($"Il y a {v1.Bagages.Count()} bagages sur le vol {v1.VolId}"); // Delete vol et bagages du vol Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.Cie}{v1.Lig}"); db.Remove(v1); db.SaveChanges(); Console.ReadLine(); } }
static void Main(string[] args) { var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder.UseLoggerFactory(MyLoggerFactory); optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["Airport"].ConnectionString); using (var db = new MyAirportContext(optionsBuilder.Options)) // using (var db = new MyAirportContext()) { // Create Console.WriteLine("Création du vol LH1232"); /*Vol v1 = new Vol * { * Cie = "LH", * Des = "BKK", * Dhc = Convert.ToDateTime("14/01/2020 16:45"), * Imm = "RZ62", * Lig = "1232", * Pkg = "R52", * Pax = 238 * };*/ Vol v1 = new Vol("LH", "1232", DateTime.Now) { Des = "BKK" }; db.Add(v1); Console.WriteLine("creation du bagage 012387364501"); /*Bagage b1 = new Bagage * { * Classe = "Y", * CodeIata = "012387364501", * DateCreation = Convert.ToDateTime("14/01/2020 12:52"), * Destination = "BEG" * }; */ Bagage b1 = new Bagage("012387364501", DateTime.Now) { Destination = "BKK" }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolId} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v1.VolId} => {v1.Cie}{v1.Lig}"); //b1.VolId = v1.VolId; db.SaveChanges(); Console.ReadLine(); // Delete vol et bagages du vol Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.Cie}{v1.Lig}"); db.Remove(v1); db.SaveChanges(); Console.ReadLine(); } Console.WriteLine("Hello World!"); }
static void Main(string[] args) { /*** * Replace OnConfigure */ DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["MyAirportDatabase"].ConnectionString); optionsBuilder.UseLoggerFactory(MyAirportLoggerFactory); DbContextOptions <MyAirportContext> optionDbContext = (DbContextOptions <MyAirportContext>)optionsBuilder.Options; using (var db = new MyAirportContext(optionDbContext)) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { cie = "LH", des = "BKK", dhc = Convert.ToDateTime("14/01/2020 16:45"), imm = "RZ62", lig = "1232", pkg = "R52", pax = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { cie = "SK", des = "CDG", dhc = Convert.ToDateTime("14/01/2020 18:20"), imm = "TG43", lig = "333", pkg = "R51", pax = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { // VolId = v1.Vol, classe = "Y", code_iata = "012387364501", date_creation = Convert.ToDateTime("14/01/2020 12:52"), destination = "BEG" }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols.OrderBy(v => v.cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.cie}{v.lig} N° {v.VolId} a destination de {v.des} part à {v.dhc} heure"); } Console.ReadLine(); //// Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v1.VolId} => {v1.cie}{v1.lig}"); b1.VolId = v1.VolId; db.SaveChanges(); Console.ReadLine(); //// Delete vol et bagages du vol // Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.cie}{v1.lig}"); // db.Remove(v1); // db.SaveChanges(); // Console.ReadLine(); } }
static void Main(string[] args) { dbContextOptionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["MyAirportDB"].ConnectionString); dbContextOptionsBuilder.UseLoggerFactory(MyAirportLoggerFactory); DbContextOptions <MyAirportContext> dbContextOptions = (DbContextOptions <MyAirportContext>)dbContextOptionsBuilder.Options; System.Console.WriteLine("MyAirport project bonjour!!"); using (var db = new MyAirportContext(dbContextOptions)) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { Cie = "LH", Des = "BKK", Dhc = Convert.ToDateTime("14/01/2020 16:45"), Imm = "RZ62", Lig = "1232", Pkg = "R52", Pax = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { Cie = "SK", Des = "CDG", Dhc = Convert.ToDateTime("14/01/2020 18:20"), Imm = "TG43", Lig = "333", Pkg = "R51", Pax = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { Classe = "Y", CodeIata = "012387364501", DateCreation = Convert.ToDateTime("14/01/2020 12:52"), Destination = "BEG" }; db.Add(b1); db.Database.EnsureCreated(); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VoldID} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageID} est modifié pour être rattaché au vol {v1.VoldID} => {v1.Cie}{v1.Lig}"); b1.VolID = v1.VoldID; db.Database.EnsureCreated(); db.SaveChanges(); Console.ReadLine(); // Delete vol et bagages du vol /*Console.WriteLine($"Suppression du vol {v1.VoldID} => {v1.Cie}{v1.Lig}"); * db.Remove(v1); * db.Database.EnsureCreated(); * db.SaveChanges(); * Console.ReadLine();*/ } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); System.Console.WriteLine("MyAirport project bonjour!!"); var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder.UseSqlite(ConfigurationManager.ConnectionStrings["MyAirportContext"].ConnectionString); using (var db = new MyAirportContext(optionsBuilder.Options)) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { Cie = "LH", Des = "BKK", Dhc = Convert.ToDateTime("14/01/2020 16:45"), Imm = "RZ62", Lig = "1232", Pkg = "R52", Pax = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { Cie = "SK", Des = "CDG", Dhc = Convert.ToDateTime("14/01/2020 18:20"), Imm = "TG43", Lig = "333", Pkg = "R51", Pax = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { Classe = "Y", CodeIata = "012387364501", DateCreation = Convert.ToDateTime("14/01/2020 12:52"), Destination = "BEG" }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols .OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolId} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v1.VolId} => {v1.Cie}{v1.Lig}"); } }
static void Main(string[] args) { var connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; var optionsBuilder = new DbContextOptionsBuilder <MyAirportContext>(); optionsBuilder .UseSqlServer(connectionString) .UseLoggerFactory(MyLoggerFactory); ILogger logger = MyLoggerFactory.CreateLogger <Program>(); System.Console.WriteLine("MyAirport project bonjour!!"); using (var db = new MyAirportContext(optionsBuilder.Options)) { // Create Console.WriteLine("Création du vol LH1232"); Vol v1 = new Vol { Cie = "LH", Des = "BKK", Dhc = Convert.ToDateTime("14 January 2020 4:45:00 PM"), Imm = "RZ62", Lig = "1232", Pkg = "R52", Pax = 238 }; db.Add(v1); Console.WriteLine("Creation vol SQ333"); Vol v2 = new Vol { Cie = "SK", Des = "CDG", Dhc = Convert.ToDateTime("14 January 2020 6:45:00 PM"), Imm = "TG43", Lig = "333", Pkg = "R51", Pax = 423 }; db.Add(v2); Console.WriteLine("creation du bagage 012387364501"); Bagage b1 = new Bagage { Classe = "Y", CodeIata = "012387364501", DateCreation = Convert.ToDateTime("14 January 2020 5:45:00 PM"), Destination = "BEG" }; db.Add(b1); db.SaveChanges(); Console.ReadLine(); // Read Console.WriteLine("Voici la liste des vols disponibles"); var vol = db.Vols.OrderBy(v => v.Cie); foreach (var v in vol) { Console.WriteLine($"Le vol {v.Cie}{v.Lig} N° {v.VolId} a destination de {v.Des} part à {v.Dhc} heure"); } Console.ReadLine(); // Update Console.WriteLine($"Le bagage {b1.BagageId} est modifié pour être rattaché au vol {v1.VolId} => {v1.Cie}{v1.Lig}"); b1.VolId = v1.VolId; db.SaveChanges(); Console.ReadLine(); // Delete vol et bagages du vol Console.WriteLine($"Suppression du vol {v1.VolId} => {v1.Cie}{v1.Lig}"); db.Remove(v1); db.SaveChanges(); Console.ReadLine(); } }