Beispiel #1
0
        public IEnumerable Add() // works out what rooms are free and returns them in a Table
        {
            DateTime startdate = BookingFrom;
            DateTime enddate   = BookingTo;

            using (var context = new Hotel_Reservation_SystemEntities())


            {
                var bookings = context.Bookings.ToList()
                               .Where(b =>
                                      (startdate >= Convert.ToDateTime(b.BookingFrom) &&
                                       enddate <= Convert.ToDateTime(b.BookingTo) ||
                                       startdate <= Convert.ToDateTime(b.BookingFrom) &&
                                       Convert.ToDateTime(b.BookingTo) <= enddate));

                if (bookings != null)
                {
                    var bookingList = bookings.ToList();
                    var theRooms    = context.Rooms.ToList();

                    FreeRoomDetails = theRooms;

                    for (var i = 0; i < theRooms.Count; i++)
                    {
                        for (var j = 0; j < bookingList.Count; j++)
                        {
                            if (theRooms[i].RoomID == bookingList[j].RoomIDFK)
                            {
                                theRooms.Remove(theRooms[i]);
                            }
                        }
                    }

                    var dgvRooms = from r in theRooms
                                   select
                                   new
                    {
                        r.RoomID,
                        r.SingleBeds,
                        r.DoubleBeds,
                        r.Tarrif1Person,
                        r.Tarrif2People,
                        r.TarrifExtraPerson
                    };
                    //  MessageBox.Show("There Are " + Convert.ToInt16(theRooms.Count) + " " + "  Rooms Available");

                    return(dgvRooms.ToList());
                }
            }
            return(new List <string>());
        }
Beispiel #2
0
        public void NewGuest() // adds a new guest on click of create booking and links it to the rest of the guests booking
        {
            using (var context = new Hotel_Reservation_SystemEntities())

            {
                var bookingID = context.Bookings.Select(b => b.BookingID).ToList().LastOrDefault();
                var guest     = new Guest
                {
                    Name        = this.Name,
                    Email       = this.Email,
                    BookingIDFK = bookingID
                };
                context.Guests.Add(guest);
                context.SaveChanges();
            }
        }
Beispiel #3
0
        public void NewBooking() // creates a new booking on click of create booking
        {
            using (var context = new Hotel_Reservation_SystemEntities())
            {
                var booking = new Booking();
                booking.BookingFrom = this.BookingFrom.ToString("dd-MM-yyyy");
                booking.BookingTo   = this.BookingTo.ToString("dd-MM-yyyy");
                booking.NumOfGuests = this.GuestNumbers;
                booking.BookingDate = DateTime.Today.Date.ToString("dd-MM-yyyy");

                booking.RoomBooked = this.RoomNumandCost;
                booking.RoomCost   = this._roomcost;
                booking.RoomIDFK   = Convert.ToInt32(_roomSelected);
                context.Bookings.Add(booking);
                context.SaveChanges();
            }
        }