Example #1
0
        public string GetInfo(string univerName)
        {
            var univers      = GenerateUnivers();
            var teacherLogic = new TeacherLogic();
            var teachers     = teacherLogic.GenerateTeachers();
            var studentLogic = new StudentLogic();
            var students     = studentLogic.GenerateStudents();

            var univer = univers
                         .SingleOrDefault(u => u.Name == univerName);

            if (univer == null)
            {
                throw new Exception(" University with univerName = " +
                                    $"{univerName} was not found. ");
            }
            int studentsCount = students
                                .Count(s => s.UniverId == univer.Id);
            int teachersCount = teachers
                                .Count(t => t.UniverId == univer.Id);

            return($" The {univer.FullName} ({univer.Name}) " +
                   $"has {studentsCount} students and " +
                   $"{teachersCount} teachers. ");
        }
Example #2
0
        public IEnumerable <string> GetAllInfo()
        {
            var univers      = GenerateUnivers();
            var teacherLogic = new TeacherLogic();
            var teachers     = teacherLogic.GenerateTeachers();
            var studentLogic = new StudentLogic();
            var students     = studentLogic.GenerateStudents();

            var univerTeachersStudents =
                from univer in univers
                join teacher in teachers on univer.Id equals teacher.UniverId
                join student in students on univer.Id equals student.UniverId
                select new UniverStudentTeacher(univer, teacher, student);

            var groups = univerTeachersStudents
                         .GroupBy(x => x.Univer, elem => new { elem.Teacher, elem.Student })
                         .ToList();

            List <string> univerTeachStudList = new List <string>();

            foreach (var gr in groups)
            {
                var teachersGr = gr
                                 .Where(t => t != null && t.Teacher != null)
                                 .Select(t => t.Teacher)
                                 .Distinct()
                                 .ToList();

                var teacherStr = GetTeacherDescription(teachersGr);

                var studentsGr = gr
                                 .Where(s => s?.Student != null)
                                 .Select(s => s.Student)
                                 .Distinct()
                                 .ToList();

                var sNameList = GetStudentDescription(studentsGr);

                univerTeachStudList
                .Add($" The {gr.Key.FullName} has " +
                     $" {teacherStr} and " +
                     $" {sNameList}. ");
            }

            return(univerTeachStudList);
        }
Example #3
0
        public IEnumerable <string> GetAllUnivers()
        {
            var univers      = GenerateUnivers();
            var teacherLogic = new TeacherLogic();
            var teachers     = teacherLogic.GenerateTeachers();
            var studentLogic = new StudentLogic();
            var students     = studentLogic.GenerateStudents();

            List <string> univTeachSudList = new List <string>();

            foreach (var univer in univers)
            {
                int teachersCount = teachers.Count(t => t.UniverId == univer.Id);
                int studentsCount = students.Count(s => s.UniverId == univer.Id);
                univTeachSudList.Add($" The {univer.FullName} " +
                                     $"({univer.Name}) has " +
                                     $"{teachersCount} teachers and " +
                                     $"{studentsCount} students. ");
            }
            return(univTeachSudList);
        }