예제 #1
0
        public void CreateSlotView()
        {
            Console.WriteLine("--- Create slot ---");

            RoomController  roomController  = new RoomController();
            StaffController staffController = new StaffController();

            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!");
                    if (Utils.ValidateTime(time) && !time.EndsWith(":00"))
                    {
                        Console.WriteLine("Time must be at the start of the hour.");
                    }
                    if (!(Convert.ToInt32(time.Substring(0, 2)) >= 9 && Convert.ToInt32(time.Substring(0, 2)) <= 14))
                    {
                        Console.WriteLine("Time must be between the school working hours of 9am to 2pm.");
                    }
                }

                firstTimeTry = false;

                Console.WriteLine("Enter time for slot (hh:mm): ");
                time = Console.ReadLine();
            } while (!Utils.ValidateTime(time) || !time.EndsWith(":00") || !(Convert.ToInt32(time.Substring(0, 2)) >= 9 && Convert.ToInt32(time.Substring(0, 2)) <= 14));

            bool   firstStaffTry = true;
            string staffId       = null;

            do
            {
                if (!firstStaffTry)
                {
                    Console.WriteLine($"{staffId} is not a valid staff. Please try again!");
                }
                firstStaffTry = false;

                Console.WriteLine("Enter staff ID: ");
                staffId = Console.ReadLine();
            } while (!(staffController.CheckIfUserExists(staffId) && staffId.StartsWith('e')));

            var      room     = roomController.GetRoom(roomId);
            var      staff    = staffController.GetUser(staffId);
            DateTime starTime = DateTime.ParseExact($"{date} {time}:00", "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            SlotModel slot = new SlotModel(room, starTime, staff);

            SlotController slotController = new SlotController();

            if (!slotController.CheckIfSlotExists(slot))
            {
                slotController.CreateSlot(slot);
                Console.WriteLine("Slot has been created successfully.");
            }
            else
            {
                Console.WriteLine($"Slot already exists for {roomId} at {date} {time}");
            }
        }