//CALLED FROM STAFF MENU public static void CheckRoomAvailability() { DateTime dateOnly; DateTime? dateOnlyNullable; List <Slot> slotList = new SlotManager().SlotList; Console.WriteLine("---Room availability---"); Console.Write("Enter date for room availability (dd-mm-yyyy): "); string inputDate = Console.ReadLine(); //VALIDATE THE DATE dateOnlyNullable = Slot.ValidateDate(inputDate); if (!(dateOnlyNullable.HasValue)) { Console.WriteLine("Invalid Date"); return; } else { //Cast nullable to normal dateOnly = (DateTime)dateOnlyNullable; } //This LINQ will return a list of roomIDs availible to be booked, with duplicates removed var resultRoomList = from Slot slot in slotList where slot.StartTime.Date == dateOnly.Date && slot.BookedInStudentID == null group slot.RoomID by slot.RoomID into roomGroup orderby roomGroup.Key select roomGroup.Key; PrintRoomAvailability(resultRoomList.ToList(), "Rooms available on " + dateOnly.ToString("dd-MM-yyy"), "<no rooms availible>"); }
//Check the ammount of bookings a room has for a given day public static bool ValidateRoomBookingCount(String roomID, DateTime dateOnly) { List <Slot> slotList = new SlotManager().SlotList; var resultSlotList = from Slot slot in slotList where slot.StartTime.Date == dateOnly.Date && slot.RoomID == roomID select slot; if (resultSlotList.Count() >= MiscellaneousUtilities.ROOM_DAILY_BOOKING_LIMIT) { return(false); } else { return(true); } }
//Check the ammount of bookings a student has for a given day public static bool ValidateStudentBookingCount(String inputStudentID, DateTime dateOnly) { List <Slot> slotList = new SlotManager().SlotList; var resultSlotList = from Slot slot in slotList where slot.StartTime.Date == dateOnly.Date && slot.BookedInStudentID == inputStudentID select slot; if (resultSlotList.Count() >= MiscellaneousUtilities.STUDENT_DAILY_BOOKING_LIMIT) { return(false); } else { return(true); } }
//CALLED FROM STUDENT MENU public static void CheckStaffAvailability() { DateTime dateOnly; DateTime? dateOnlyNullable; List <Slot> slotList = new SlotManager().SlotList; Console.WriteLine("---Staff availability---"); Console.Write("Enter date for room availability (dd-mm-yyyy): "); string inputDate = Console.ReadLine(); Console.Write("Enter staff ID: "); string inputStaffID = Console.ReadLine(); //VALIDATE THE DATE dateOnlyNullable = Slot.ValidateDate(inputDate); if (!(dateOnlyNullable.HasValue)) { Console.WriteLine("Invalid Date"); return; } else { //Cast nullable to normal dateOnly = (DateTime)dateOnlyNullable; } //VALIDATE THE STAFF ID if (!(ValidateEngine.ValidateStaffId(inputStaffID))) { Console.WriteLine("Invalid StaffID"); return; } //This LINQ will return a list of roomIDs availible to be booked, with duplicates removed var resultRoomList = from Slot slot in slotList where slot.StartTime.Date == dateOnly.Date && slot.BookedInStudentID == null && slot.StaffID == inputStaffID select slot; PrintStaffAvailability(resultRoomList.ToList(), "Staff " + inputStaffID + " availability on " + dateOnly.ToString("dd-MM-yyy"), "<no slots availible>"); }