public void DeleteReservation(int customerID)
        {
            var reservationToDelete      = new Reservation();
            var paymentInfoToDelete      = new Payment();
            var reservationRoomsToDelete = new ReservationRoom();
            var customerToDelete         = new Customer();

            using (HotelDBContext context = new HotelDBContext())
            {
                try
                {
                    reservationToDelete      = context.Reservations.SingleOrDefault(r => r.CustomerID == customerID);
                    reservationRoomsToDelete = context.ReservationRooms.SingleOrDefault(r => r.ReservationRoomsID == reservationToDelete.ReservationRoomsID);
                    customerToDelete         = context.Customers.SingleOrDefault(r => r.CustomerID == reservationToDelete.CustomerID);

                    paymentInfoToDelete = context.Payments.SingleOrDefault(p => p.PaymentID == reservationToDelete.PaymentID);

                    context.Entry(reservationToDelete).State      = System.Data.Entity.EntityState.Deleted;
                    context.Entry(reservationRoomsToDelete).State = System.Data.Entity.EntityState.Deleted;
                    context.Entry(paymentInfoToDelete).State      = System.Data.Entity.EntityState.Deleted;
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                }
            }
        }
        public void DeleteCustomer(int customerID)
        {
            var reservationsToDelete     = new List <Reservation>();
            var paymentsInfoToDelete     = new Payment();
            var reservationRoomsToDelete = new ReservationRoom();

            using (HotelDBContext context = new HotelDBContext())
            {
                var customer = context.Customers.FirstOrDefault(c => c.CustomerID == customerID);
                try
                {
                    reservationsToDelete = context.Reservations.Where(r => r.CustomerID == customer.CustomerID).ToList();

                    foreach (var reservation in reservationsToDelete)
                    {
                        context.Entry(reservation).State = System.Data.Entity.EntityState.Deleted;
                        reservationRoomsToDelete         = context.ReservationRooms.SingleOrDefault(r => r.ReservationRoomsID == reservation.ReservationRoomsID);
                        context.Entry(reservationRoomsToDelete).State = System.Data.Entity.EntityState.Deleted;
                        paymentsInfoToDelete = context.Payments.FirstOrDefault(p => p.PaymentID == reservation.PaymentID);
                        context.Entry(paymentsInfoToDelete).State = System.Data.Entity.EntityState.Deleted;
                    }
                    context.Entry(customer).State = System.Data.Entity.EntityState.Deleted;
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                }
                MessageBox.Show("Customer Have been Deleted");
            }
        }
        public void RemoveAllBookingsWichIsntPayedIn10Days()
        {
            var reservationToDelete      = new Reservation();
            var paymentInfoToDelete      = new Payment();
            var reservationRoomsToDelete = new ReservationRoom();
            var customerToDelete         = new Customer();
            var anwser = "Yes";

            using (HotelDBContext context = new HotelDBContext())
            {
                var payment = context.Payments.Where(r => r.LastDayToPay < DateTime.Now).ToList();
                foreach (var payed in payment)
                {
                    if (payed.Paid == "No")
                    {
                        try
                        {
                            reservationToDelete      = context.Reservations.SingleOrDefault(r => r.PaymentID == payed.PaymentID);
                            reservationRoomsToDelete = context.ReservationRooms.SingleOrDefault(r => r.ReservationRoomsID == reservationToDelete.ReservationRoomsID);
                            customerToDelete         = context.Customers.SingleOrDefault(r => r.CustomerID == reservationToDelete.CustomerID);

                            paymentInfoToDelete = payed;
                            anwser = "No";



                            context.Entry(reservationToDelete).State      = System.Data.Entity.EntityState.Deleted;
                            context.Entry(reservationRoomsToDelete).State = System.Data.Entity.EntityState.Deleted;
                            context.Entry(paymentInfoToDelete).State      = System.Data.Entity.EntityState.Deleted;
                            context.Entry(reservationToDelete).State      = System.Data.Entity.EntityState.Deleted;
                            context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        finally
                        {
                        }
                    }
                }
                if (anwser == "No")
                {
                    MessageBox.Show("Customers who haven't payed for 10 days since there booking have been removed");
                }
            }
        }
        private void btnBookTheRoom_Click(object sender, EventArgs e)
        {
            if (lstAvaibleRooms.SelectedIndex > -1)
            {
                var selectedRoomType = GetRoomType(lstAvaibleRooms.Text);
                int days             = Convert.ToInt32((checkOutEndDate.Value - CheckInStartDate.Value).TotalDays);

                var bookingDate  = DateTime.Today;
                var lastDayToPay = bookingDate.AddDays(10);

                using (HotelDBContext context = new HotelDBContext())
                {
                    Room room = context.Rooms.FirstOrDefault(r => r.RoomTypeID == selectedRoomType.RoomTypeID);

                    ReservationRoom reservationRoom = new ReservationRoom
                    {
                        RoomID = room.RoomID
                    };
                    Payment payment = new Payment
                    {
                        PaymentAmount = selectedRoomType.PricePerDay * days,
                        Paid          = "No",
                        BookingDate   = DateTime.Today,
                        LastDayToPay  = lastDayToPay
                    };
                    Reservation reservation = new Reservation
                    {
                        StartDate          = CheckInStartDate.Value,
                        EndDate            = checkOutEndDate.Value,
                        CustomerID         = mainForm.GetSelectedCustomerID(),
                        ReservationRoomsID = reservationRoom.ReservationRoomsID,
                        PaymentID          = payment.PaymentID
                    };

                    context.ReservationRooms.Add(reservationRoom);
                    context.Payments.Add(payment);
                    context.Reservations.Add(reservation);
                    context.SaveChanges();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("You have not selected a room");
            }
        }