private static void RegisterStudentToCourse() { { bool shouldAbort = false; do { Clear(); WriteLine("Elev (personnr):"); string socialSecurityNumber = ReadLine(); WriteLine(); WriteLine("Kurs (titel):"); string title = ReadLine(); WriteLine(); WriteLine("Är detta korrekt? (J)a eller (N)ej"); bool hasInvalidInput = true; do { ConsoleKeyInfo keyPressed = ReadKey(true); switch (keyPressed.Key) { case ConsoleKey.J: hasInvalidInput = false; shouldAbort = true; Clear(); Course course = Context .Course .FirstOrDefault(x => x.Title == title); Student student = Context .Student .FirstOrDefault(x => x.SocialSecurityNumber == socialSecurityNumber); if (student == null) { WriteLine("Elev hittades ej"); } else if (course == null) { WriteLine("Kursen hittades ej"); } else { CourseStudent studentCourse = new CourseStudent(student.Id); course.StudentCourse.Add(studentCourse); Context.SaveChanges(); WriteLine("Elev tillagd till kurs"); } Thread.Sleep(2000); break; case ConsoleKey.N: hasInvalidInput = false; break; } } while (hasInvalidInput); } while (shouldAbort == false); } }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; HogwartsContext context = services.GetRequiredService <HogwartsContext>(); if (context.Atractions.Count() == 0) { context.Add(new Atractions() { Name = "בלונה הוגסמיד, כל אחד יכול למצוא את המתקנים שילהיבו אותו. באתר מגוון אטרקציות לילדים,נוער ולכל אוהבי האקסטרים", Kind = 1, Address = "https://i.ytimg.com/vi/3-81zUqPqE4/maxresdefault.jpg", Age = 9, DurationTime = 0, TicketPrice = 90, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 1) { context.Add(new Atractions() { Name = "פונדק שלושת המטאטאים", Kind = 1, Address = "https://via-arkadia.co.il/wp-content/uploads/2016/01/NITHAN_THAI_007-839x391.jpg", Age = 8, DurationTime = 90, TicketPrice = 80, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 2) { context.Add(new Atractions() { Name = "הגלידריה של פלוריאן פורטסקיו", Kind = 1, Address = "http://www.welovebrighton.com/wp-content/uploads/2014/07/gelato1.jpg", Age = 0, DurationTime = 0, TicketPrice = 30, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 3) { context.Add(new Atractions() { Name = "חורשת ווילס ", Kind = 1, Address = "https://www.izikbi.com/files/catalog/item/thumbsrc/c5000/B0066748-B0066750-Pano-e%20copy.jpg", Age = 7, DurationTime = 0, TicketPrice = 15, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 4) { context.Add(new Atractions() { Name = "האזור האסור- ספריה קסומה ", Kind = 1, Address = "https://cdn-image.travelandleisure.com/sites/default/files/styles/1600x1000/public/1476719873/Strahov-Monastery-LIBRARY1016.jpg?itok=njrX149R", Age = 6, DurationTime = 0, TicketPrice = 60, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 5) { context.Add(new Atractions() { Name = "חנות ההוקוס מוקוס של האחים וויזלי ", Kind = 1, Address = "https://img.buzzfeed.com/buzzfeed-static/static/2014-06/21/9/enhanced/webdr09/original-grid-image-20405-1403358828-6.jpg?crop=990:655;0,2&downsize=400:*&output-format=auto&output-quality=auto", Age = 5, DurationTime = 0, TicketPrice = 10, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 6) { context.Add(new Atractions() { Name = "האגם הגדול- צלילה חופשית ", Kind = 1, Address = "https://images.pottermore.com/bxd3o8b291gf/6iG89kbQNa8gCOckq2ocQa/cfa3133476d2d4f444752b293683c56b/HarryPotter_PM_B4C26M1_HarryInGreatLakeMerpeopleSecondTask_Moment.jpg?w=1200", Age = 4, DurationTime = 150, TicketPrice = 150, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 7) { context.Add(new Atractions() { Name = "טורניר הקוסמים המשולש- המבוך ", Kind = 1, Address = "https://live.staticflickr.com/3055/2745280437_cb6b2b6fb4_z.jpg", Age = 3, DurationTime = 60, TicketPrice = 50, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 8) { context.Add(new Atractions() { Name = "קווידיץ'- משחקי קבוצות ", Kind = 1, Address = "https://i.pinimg.com/originals/a5/94/0c/a5940cceb9e7917424818d4039f64626.jpg", Age = 2, DurationTime = 45, TicketPrice = 20, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 9) { context.Add(new Atractions() { Name = "הערגוג- מתקן העכביש ", Kind = 1, Address = "https://i.ytimg.com/vi/i9xb2O6CIcs/maxresdefault.jpg", Age = 1, DurationTime = 15, TicketPrice = 40, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 10) { context.Add(new Atractions() { Name = "מסלול סקי מכשולים- בעקבות הסניץ' המוזהב ", Kind = 1, Address = "https://bookstr.com/wp-content/uploads/2018/02/hpsnow.jpg", Age = 10, DurationTime = 50, TicketPrice = 70, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 11) { context.Add(new Atractions() { Name = "מתנפחים ", Kind = 1, Address = "https://ae01.alicdn.com/kf/HTB1vm4aIXXXXXbCXVXXq6xXFXXXc/bouncy-castle-inflatable-Harry-Potter-castles-B1016.jpg", Age = 11, DurationTime = 0, TicketPrice = 15, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 12) { context.Add(new Atractions() { Name = " תחרויות פאזלים ", Kind = 1, Address = "https://images.esellerpro.com/2489/I/173/754/7/15171.jpg", Age = 19, DurationTime = 50, TicketPrice = 35, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 13) { context.Add(new Atractions() { Name = "חדר בריחה- היער האסור ", Kind = 1, Address = "http://hportal.co.il/images/editor/yaar.png", Age = 17, DurationTime = 0, TicketPrice = 100, //Title }); context.SaveChanges(); } if (context.Atractions.Count() == 14) { context.Add(new Atractions() { Name = "הבקתה של האגריד- ספא וטיפולים ", Kind = 1, Address = "http://www.harrypotternet.co.il/setting_HagridHut_b.jpg", Age = 16, DurationTime = 150, TicketPrice = 450, //Title }); context.SaveChanges(); } } host.Run(); }
private static void AddStudent() { bool Exit = false; while (!Exit) { Write("Förnamn: "); string firstName = ReadLine(); Write("Efternamn: "); string lastName = ReadLine(); Write("Personnummer: "); string socialSecurityNumber = ReadLine(); Write("Gatuadress: "); string streetAddress = ReadLine(); Write("Stad: "); string city = ReadLine(); Write("Postnummer: "); string postCode = ReadLine(); WriteLine(); WriteLine("Är detta korrekt? (J)a eller (N)ej \n (L)ämna utan att spara"); ConsoleKeyInfo menuChoice = ReadKey(true); Clear(); switch (menuChoice.Key) { case ConsoleKey.J: Student student = FetchStudentAndAddress(x => x.SocialSecurityNumber == socialSecurityNumber); if (student == null) { Address address = new Address(streetAddress, city, postCode); Student newStudent = new Student(firstName, lastName, socialSecurityNumber, address); Context.Students.Add(newStudent); Context.SaveChanges(); Clear(); WriteLine("Elev registrerad"); } else { Clear(); WriteLine("Elev finns redan"); } Thread.Sleep(1200); Clear(); Exit = true; break; case ConsoleKey.N: Clear(); Exit = true; AddStudent(); break; case ConsoleKey.L: Exit = true; break; default: break; } } }
private static void AddStudentToCourse() { Clear(); bool customerExists = false; bool incorrectKey = true; bool shouldNotExit = true; do { WriteLine("Elev (personnummer): "); string socialSecurityNumber = ReadLine(); WriteLine("Kurs: "); string courseTitle = ReadLine(); WriteLine("Är detta korrekt? (J)a eller (N)ej"); ConsoleKeyInfo consoleKeyInfo; do { consoleKeyInfo = ReadKey(true); incorrectKey = !(consoleKeyInfo.Key == ConsoleKey.J || consoleKeyInfo.Key == ConsoleKey.N); } while (incorrectKey); if (consoleKeyInfo.Key == ConsoleKey.J) { var student = context.Students.FirstOrDefault(a => a.SocialSecurityNumber == socialSecurityNumber); var course = context.Courses.FirstOrDefault(m => m.Title == courseTitle); if (student != null) { StudentCourse studentCourse = new StudentCourse(student); course.Students.Add(studentCourse); context.SaveChanges(); shouldNotExit = false; Clear(); WriteLine("Student registrerad på kurs"); Thread.Sleep(1000); } else if (student == null) { shouldNotExit = false; Clear(); WriteLine("Student ej registrerad"); Thread.Sleep(1000); } } Clear(); } while (shouldNotExit); }