public override Controller Execute(Controller controller) { var faculty = controller.Faculty; //курс Console.Write("Enter the course( "); foreach (var c in faculty.GetCourses()) { Console.Write($"{c.Number} "); } Console.Write("): "); var str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !faculty.Contains(number)) { Console.Write("Enter the available course number: "); str = Console.ReadLine(); } int n = Convert.ToInt32(str); var course = faculty.GetCourse(n); //потік Console.WriteLine("Choose the stream: "); var streams = course.Streams; for (int i = 0; i < streams.Count; i++) { Console.WriteLine($"{i}. {streams[i].Speciality.Name};"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < streams.Count)) { Console.Write("Choose the available stream number: "); str = Console.ReadLine(); } var stream = streams[Convert.ToInt32(str)]; //Предмет Console.WriteLine("Choose the subject: "); var subjects = Subject.GetAll(); for (int i = 0; i < subjects.Count; i++) { Console.WriteLine($"{i}. {subjects[i].Name};"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < subjects.Count)) { Console.Write("Choose the subject from the list: "); str = Console.ReadLine(); } var subject = subjects[Convert.ToInt32(str)]; //Вчитель Console.WriteLine("Choose the teacher: "); var teachers = faculty.Teachers.Where(x => x.HoursOfWork > faculty.Schedule.CountTeacherHours(x)).ToList(); for (int i = 0; i < teachers.Count; i++) { Console.WriteLine($"{i}. {teachers[i].Surname} {teachers[i].Name} {teachers[i].MiddleName};"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < teachers.Count)) { Console.Write("Choose the teacher from the list: "); str = Console.ReadLine(); } var teacher = teachers[Convert.ToInt32(str)]; //Час var freeTime = new List <TimeSlot>(); foreach (var slot in TimeSlot.GetAll()) { var auditoryCheck = faculty.Auditoriums.Any(x => !faculty.Schedule.Contains(x, slot)); if (!faculty.Schedule.Contains(stream, slot) && !faculty.Schedule.Contains(teacher, slot) && !faculty.Schedule.Contains(stream.AsEnumerable(), slot) && auditoryCheck) { freeTime.Add(slot); } } Console.WriteLine("Choose the day and time:"); for (int i = 0; i < freeTime.Count; i++) { Console.WriteLine($"{i}. {freeTime[i]}"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < freeTime.Count)) { Console.Write("Choose the day from the list: "); str = Console.ReadLine(); } var time = freeTime[Convert.ToInt32(str)]; //аудиторія Console.WriteLine("Choose the auditorium: "); var auditoriums = faculty.Auditoriums.Where(x => !faculty.Schedule.Contains(x, time)).ToList(); for (int i = 0; i < auditoriums.Count; i++) { Console.WriteLine($"{i}. {auditoriums[i].Name};"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < auditoriums.Count)) { Console.Write("Choose the auditorium from the list: "); str = Console.ReadLine(); } var auditorium = auditoriums[Convert.ToInt32(str)]; var lecture = new Lecture(teacher, time, subject, auditorium, stream); faculty.Schedule.Add(lecture); return(controller); }
public override Controller Execute(Controller controller) { var faculty = controller.Faculty; //курс Console.Write("Enter the course( "); foreach (var c in faculty.GetCourses()) { Console.Write($"{c.Number} "); } Console.Write("): "); var str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !faculty.Contains(number)) { Console.Write("Enter the available course number: "); str = Console.ReadLine(); } int n = Convert.ToInt32(str); var course = faculty.GetCourse(n); //потік Console.WriteLine("Choose the stream: "); var streams = course.Streams; for (int i = 0; i < streams.Count; i++) { Console.WriteLine($"{i}. {streams[i].Speciality.Name};"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < streams.Count)) { Console.Write("Choose the available stream number: "); str = Console.ReadLine(); } var stream = streams[Convert.ToInt32(str)]; //Група Console.WriteLine("Choose the group: "); var groups = stream.Groups; for (int i = 0; i < groups.Count; i++) { Console.WriteLine($"{i}. {groups[i].Name};"); } Console.Write("-> "); str = Console.ReadLine(); while (!int.TryParse(str, out int number) || !(number > -1 && number < groups.Count)) { Console.Write("Choose the group from the list: "); str = Console.ReadLine(); } var group = groups[Convert.ToInt32(str)]; foreach (var time in TimeSlot.GetAll()) { var lecture = faculty.Schedule .Lectures .FirstOrDefault(x => x.Stream == group.Stream && x.TimeSlot == time); var practice = faculty.Schedule .Practices .FirstOrDefault(x => x.Group == group && x.TimeSlot == time); if (lecture is { })