예제 #1
0
        public void DeleteSlotView()
        {
            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 != null)
            {
                if (slot.student == null)
                {
                    slotController.DeleteSlot(slot);
                    Console.WriteLine("Slot has been deleted successfully.");
                }
                else
                {
                    Console.WriteLine("Unable to delete booked slot");
                }
            }
            else
            {
                Console.WriteLine("Slot does not exists!");
            }
        }