private static void PerformInspection() { bool reservationExists = false; WriteLine("Registreringsnummer: "); string registrationNumber = ReadLine(); using FordonsBesiktningContext context = new FordonsBesiktningContext(); var correctReservation = context.Reservations.Where(r => r.RegistrationNumber == registrationNumber); foreach (var reservation in correctReservation) { if (reservation.RegistrationNumber == registrationNumber) { reservationExists = true; } } if (reservationExists) { bool incorrectKey = true; Console.WriteLine("Fordonet godkänt? (J)a eller (N)ej"); ConsoleKeyInfo inputKey; do { inputKey = ReadKey(true); incorrectKey = !(inputKey.Key == ConsoleKey.J || inputKey.Key == ConsoleKey.N); } while (incorrectKey); Inspection inspection = new Inspection(registrationNumber); if (inputKey.Key == ConsoleKey.J) { inspection.Pass(); context.Inspections.Add(inspection); WriteLine("Inspektion godkänd"); Thread.Sleep(1000); context.SaveChanges(); } if (inputKey.Key == ConsoleKey.N) { inspection.Fail(); context.Inspections.Add(inspection); WriteLine("Inspektion Ej godkänd"); Thread.Sleep(1000); context.SaveChanges(); } } else { Console.WriteLine("Reservation saknas"); Thread.Sleep(1000); } }