public IActionResult Subjects()
        {
            var referenceId = User.Claims.FirstOrDefault(x => x.Type.Equals(Constants.Claims.ReferenceId));
            var deanery     = DeaneryManager.GetById(referenceId.Value);
            var sheets      = ExamSheetManager.FindClosedForFaculty(deanery.FacultyId);
            var subjectsIds = sheets.Select(x => x.SubjectId).Distinct().ToList();
            var subjects    = SubjectManager.GetByIdList(subjectsIds);
            var model       = new SubjectStatisticViewModel();

            model.SubjectList = new List <SelectListItem>();
            foreach (var subject in subjects)
            {
                model.SubjectList.Add(new SelectListItem()
                {
                    Text = subject.Name, Value = subject.Id
                });
            }
            model.FacultyId = deanery.FacultyId;
            return(View(model));
        }
        protected virtual GroupStatisticViewModel CreateGroupStatisticViewModel(IEnumerable <ExamSheetModel> sheets)
        {
            var model       = new GroupStatisticViewModel();
            var groupsIds   = sheets.Select(x => x.GroupId).Distinct().ToList();
            var subjectsIds = sheets.Select(x => x.SubjectId).Distinct().ToList();
            var teachersIds = sheets.Select(x => x.TeacherId).Distinct().ToList();
            var teachers    = TeacherManager.GetByIdList(teachersIds);
            var groups      = GroupManager.GetByIdList(groupsIds);
            var subjects    = SubjectManager.GetByIdList(subjectsIds);

            model.GroupList    = groups.OrderBy(x => x.Name).Select(x => new SelectListItem(x.Name, x.Id)).ToList();
            model.SemesterList = new List <SelectListItem>();
            model.SubjectList  = new List <SelectListItem>();
            model.TeacherList  = new List <SelectListItem>();
            model.YearList     = new List <SelectListItem>();

            foreach (var group in groups)
            {
                var groupSheets = sheets.Where(x => x.GroupId == group.Id).ToList();
                if (!groupSheets?.Any() ?? true)
                {
                    continue;
                }

                var listGroup = new SelectListGroup()
                {
                    Name = group.Name
                };
                foreach (var sheet in groupSheets)
                {
                    var subject          = subjects.FirstOrDefault(x => x.Id == sheet.SubjectId);
                    var subjectValidName = subject.Name.Replace('\'', ' ').Replace('-', ' ').Replace(':', ' ').Replace('.', ' ').Replace('(', ' ').Replace(')', ' ');
                    if (subject != null && !model.SubjectList.Any(x => x.Value == subject.Id && x.Group.Name == group.Name))
                    {
                        model.SubjectList.Add(new SelectListItem()
                        {
                            Text = subjectValidName, Value = subject.Id, Group = listGroup
                        });
                    }

                    var subjectGroupName = string.Format("{0} {1}", group.Name, subjectValidName);
                    var listGroupSubject = new SelectListGroup()
                    {
                        Name = subjectGroupName
                    };
                    if (!model.SemesterList.Any(x => x.Value == sheet.Semester.ToString() && x.Group.Name == subjectGroupName))
                    {
                        model.SemesterList.Add(new SelectListItem()
                        {
                            Text = sheet.Semester.ToString(), Value = sheet.Semester.ToString(), Group = listGroupSubject
                        });
                    }
                    if (!model.YearList.Any(x => x.Value == sheet.Year.ToString() && x.Group.Name == subjectGroupName))
                    {
                        model.YearList.Add(new SelectListItem()
                        {
                            Text = sheet.Year.ToString(), Value = sheet.Year.ToString(), Group = listGroupSubject
                        });
                    }
                    var teacher = teachers.FirstOrDefault(x => x.Id == sheet.TeacherId);
                    if (teacher != null && !model.TeacherList.Any(x => x.Value == teacher.Id && x.Group.Name == subjectGroupName))
                    {
                        model.TeacherList.Add(new SelectListItem()
                        {
                            Text = string.Format("{0} {1}", teacher.Surname, teacher.Name), Value = teacher.Id, Group = listGroupSubject
                        });
                    }
                }
            }
            return(model);
        }