Ejemplo n.º 1
0
        public static void DelBookOrUser()
        {
            Console.Clear();
            Console.WriteLine("");

            using (var context = new HotelContext())
            {
                Console.WriteLine("\n1. Slet gæst \n2. Delete Booking");
                int input1 = int.Parse(Console.ReadLine());

                switch (input1)
                {
                case 1:     // delete gæst

                    var hotelContext = context.Hotels;
                    var guestContext = context.Guests;

                    foreach (var hotelObj in hotelContext)
                    {
                        Console.WriteLine($"Hotel nr. {hotelObj.Hotel_No}, {hotelObj.Name}, {hotelObj.Address}");
                    }

                    Console.Write("\n Vælg hotel nr: ");
                    int input2 = int.Parse(Console.ReadLine());

                    var selectedHotel = context.Hotels.Find(input2);
                    var infoBooking   = context.Bookings.Where(x => x.Hotel_No == selectedHotel.Hotel_No);

                    var allGuests = infoBooking.Select(x => x);
                    foreach (var item in allGuests)
                    {
                        Console.WriteLine($"Gæst Nr. {item.Guest_No}, Værelse Nr. {item.Room_No}");
                    }

                    Console.Write("\n Vælg gæst nr. Som skal slettes: ");

                    int delGuest     = int.Parse(Console.ReadLine());
                    var originalGæst = context.Guests.Find(delGuest);
                    guestContext.Remove(originalGæst);

                    break;

                case 2:

                    var allBookings = context.Bookings;
                    foreach (var item in allBookings)
                    {
                        Console.WriteLine($"ID: {item.Booking_id}, Guest nr. {item.Guest_No}");
                    }

                    Console.Write("\nVælg ID som skal slettes: ");

                    int delBooking      = int.Parse(Console.ReadLine());
                    var originalBooking = context.Bookings.Find(delBooking);
                    allBookings.Remove(originalBooking);

                    break;

                default:
                    break;
                }

                context.SaveChanges();
            }

            Console.ReadLine();
            Console.Clear();
        }