/// <summary> /// This function helper for set Slot Controller. /// </summary> /// <returns></returns> public void SetSlotController(SlotController slotController) { this.slotController = slotController; hexagon.SetSlot(slotController.GetSlot()); slotController.SetHexagonController(this); SlotChanged?.Invoke(slotController); }
public void CancelSlotBookingView() { SlotController slotController = new SlotController(); RoomController roomController = new RoomController(); bool firstRoomTry = true; string roomId = null; do { if (!firstRoomTry) { Console.WriteLine($"Room {roomId} does not exists. Please try again!"); } firstRoomTry = false; Console.WriteLine("Enter room name: "); roomId = Console.ReadLine(); } while (!roomController.CheckIfRoomExists(roomId)); bool firstDateTry = true; string date = null; do { if (!firstDateTry) { Console.WriteLine($"{date} is not a valid date. Please try again!"); } firstDateTry = false; Console.WriteLine("Enter date for slot (dd-mm-yyyy): "); date = Console.ReadLine(); } while (!Utils.ValidateDate(date)); bool firstTimeTry = true; string time = null; do { if (!firstTimeTry) { Console.WriteLine($"{time} is not a valid time. Please try again!"); } firstTimeTry = false; Console.WriteLine("Enter time for slot (hh:mm): "); time = Console.ReadLine(); } while (!Utils.ValidateTime(time)); DateTime starTime = DateTime.ParseExact($"{date} {time}:00", "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture); SlotModel slot = slotController.GetSlot(roomId, starTime); if (slot.student != null) { slotController.CancelBooking(slot); Console.WriteLine("Slot booking has been cancelled successfully."); } else { Console.WriteLine("Slot is not booked!"); } }
public void BookSlotView() { SlotController slotController = new SlotController(); RoomController roomController = new RoomController(); StudentController studentController = new StudentController(); bool firstRoomTry = true; string roomId = null; do { if (!firstRoomTry) { Console.WriteLine($"Room {roomId} does not exists. Please try again!"); } firstRoomTry = false; Console.WriteLine("Enter room name: "); roomId = Console.ReadLine(); } while (!roomController.CheckIfRoomExists(roomId)); bool firstDateTry = true; string date = null; do { if (!firstDateTry) { Console.WriteLine($"{date} is not a valid date. Please try again!"); } firstDateTry = false; Console.WriteLine("Enter date for slot (dd-mm-yyyy): "); date = Console.ReadLine(); } while (!Utils.ValidateDate(date)); bool firstTimeTry = true; string time = null; do { if (!firstTimeTry) { Console.WriteLine($"{time} is not a valid time. Please try again!"); } firstTimeTry = false; Console.WriteLine("Enter time for slot (hh:mm): "); time = Console.ReadLine(); } while (!Utils.ValidateTime(time)); DateTime starTime = DateTime.ParseExact($"{date} {time}:00", "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture); SlotModel slot = slotController.GetSlot(roomId, starTime); if (slot != null) { if (slot.student == null) { bool firstStudentTry = true; string studentId = null; do { if (!firstStudentTry) { Console.WriteLine($"{studentId} is not a valid staff. Please try again!"); } firstStudentTry = false; Console.WriteLine("Enter student ID: "); studentId = Console.ReadLine(); } while (!(studentController.CheckIfUserExists(studentId) && studentId.StartsWith('s'))); slot.student = studentController.GetUser(studentId); if (slotController.IsBookingAllowed(slot)) { if (!slotController.HasExceededStaffBooking(slot)) { slotController.BookSlot(slot); Console.WriteLine("Slot has been booked successfully."); } else { Console.WriteLine($"Unable to book! Staff {slot.staff.userId} has already exceeded his booking capacity for {date}"); } } else { Console.WriteLine($"Unable to book! Student has already booked a slot for {date}"); } } else { Console.WriteLine("Unable to book! Slot is already booked"); } } else { Console.WriteLine("Unable to book! Slot does not exists!"); } }