public void GetAvaibleRooms()
        {
            var startDate = CheckInStartDate.Value.Date;
            var endDate   = checkOutEndDate.Value.Date;

            if (startDate == endDate || startDate > endDate || startDate < DateTime.Now)
            {
                MessageBox.Show("Something wen´t wrong when you chosed dates");
                return;
            }
            var unavaibleRooms = new List <Room>();

            lstAvaibleRooms.Items.Clear();
            using (HotelDBContext context = new HotelDBContext())
            {
                var AllRoomTypes = context.Rooms.ToList();
                foreach (var reserv in context.Reservations)
                {
                    if ((startDate >= reserv.StartDate && startDate < reserv.EndDate) || (endDate > reserv.StartDate && endDate < reserv.EndDate))
                    {
                        var reservationRooms = context.ReservationRooms.FirstOrDefault(r => r.ReservationRoomsID == reserv.ReservationRoomsID);
                        var roomID           = context.Rooms.FirstOrDefault(r => r.RoomID == reservationRooms.RoomID);
                        unavaibleRooms.Add(roomID);
                    }
                }
                var avaibleRooms = GetAvaibleRooms(AllRoomTypes, unavaibleRooms);
                foreach (var room in avaibleRooms)
                {
                    var roomTypes = context.RoomTypes.FirstOrDefault(r => r.RoomTypeID == room.RoomTypeID);
                    if (cBoxNumberOfPeople.Text == "1" && roomTypes.RoomSize == 1)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                    else if (cBoxNumberOfPeople.Text == "2" && roomTypes.RoomSize == 2)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                    else if (cBoxNumberOfPeople.Text == "3" && roomTypes.RoomSize == 3)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                    else if (cBoxNumberOfPeople.Text == "4" && roomTypes.RoomSize == 4)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                    else if (cBoxNumberOfPeople.Text == "5" && roomTypes.RoomSize == 5)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                    else if (cBoxNumberOfPeople.Text == "6" && roomTypes.RoomSize == 6)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                    else if (cBoxNumberOfPeople.SelectedIndex <= -1)
                    {
                        lstAvaibleRooms.Items.Add(roomTypes.RoomDescription);
                    }
                }
            }
        }
 public RoomType GetRoomType(string selectedRoomDescription)
 {
     using (HotelDBContext context = new HotelDBContext())
     {
         return(context.RoomTypes.FirstOrDefault(r => r.RoomDescription == selectedRoomDescription));
     }
 }
Ejemplo n.º 3
0
        public List <string> GetCustomerReservationInformationToFill(int selectedCustomerID)
        {
            var reservationInfoList = new List <string>();

            using (HotelDBContext context = new HotelDBContext())
            {
                var customer    = context.Customers.SingleOrDefault(r => r.CustomerID == selectedCustomerID);
                var reservation = context.Reservations.SingleOrDefault(r => r.CustomerID == customer.CustomerID);
                if (reservation == null)
                {
                    return(null);
                }
                var reservationRoom = context.ReservationRooms.SingleOrDefault(r => r.ReservationRoomsID == reservation.ReservationRoomsID);

                var room     = context.Rooms.SingleOrDefault(r => r.RoomID == reservationRoom.RoomID);
                var roomType = context.RoomTypes.SingleOrDefault(r => r.RoomTypeID == room.RoomTypeID);
                var payment  = context.Payments.SingleOrDefault(r => r.PaymentID == reservation.PaymentID);

                reservationInfoList.Add(roomType.RoomDescription);
                reservationInfoList.Add(room.RoomID.ToString());
                reservationInfoList.Add(reservation.StartDate.ToString());
                reservationInfoList.Add(reservation.EndDate.ToString());;
                reservationInfoList.Add(payment.PaymentAmount.ToString());
                reservationInfoList.Add(payment.Paid);
            }
            return(reservationInfoList);
        }
Ejemplo n.º 4
0
        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");
            }
        }
Ejemplo n.º 5
0
        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
                {
                }
            }
        }
Ejemplo n.º 6
0
        public List <Customer> SearchForCustomer(string searchedText)
        {
            List <Customer> searchedCustomer = new List <Customer>();

            using (HotelDBContext context = new HotelDBContext())
            {
                searchedCustomer = context.Customers.Where(c => c.LastName.StartsWith(searchedText)).ToList();
            }
            return(searchedCustomer);
        }
Ejemplo n.º 7
0
        public Customer GetCustomerInformation(int customerID)
        {
            Customer selectedCustomer = new Customer();

            using (HotelDBContext context = new HotelDBContext())
            {
                selectedCustomer = context.Customers.FirstOrDefault(c => c.CustomerID == customerID);
            }
            return(selectedCustomer);
        }
Ejemplo n.º 8
0
        public void UpdatePaymentCustomer(int customerID)
        {
            using (HotelDBContext context = new HotelDBContext())
            {
                var reservation = context.Reservations.Where(r => r.CustomerID == customerID).ToList();

                foreach (var reserv in reservation)
                {
                    var payment = context.Payments.FirstOrDefault(r => r.PaymentID == reserv.PaymentID);
                    payment.Paid = "Yes";
                }

                context.SaveChanges();
            }
            MessageBox.Show("Customers reservation is Payed");
        }
Ejemplo n.º 9
0
        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");
            }
        }
Ejemplo n.º 11
0
 public void AddNewCustomer(string firstName, string lastName, string address, string postalCode, string city, string country, string phone)
 {
     using (HotelDBContext context = new HotelDBContext())
     {
         Customer customer = new Customer
         {
             FirstName  = firstName,
             LastName   = lastName,
             Address    = address,
             PostalCode = postalCode,
             City       = city,
             Country    = country,
             Phone      = phone
         };
         context.Customers.Add(customer);
         context.SaveChanges();
     }
 }
Ejemplo n.º 12
0
        public void UpdateCustomerInformation(int customerID, string firstName, string LastName, string address, string postalCode, string city,
                                              string country, string phone)
        {
            using (HotelDBContext context = new HotelDBContext())
            {
                var customer = context.Customers.SingleOrDefault(r => r.CustomerID == customerID);

                customer.FirstName  = firstName;
                customer.LastName   = LastName;
                customer.Address    = address;
                customer.PostalCode = postalCode;
                customer.City       = city;
                customer.Country    = country;
                customer.Phone      = phone;

                context.SaveChanges();
            }
            MessageBox.Show("Customer information is saved");
        }