Пример #1
0
        private IEnumerable <SelectListItem> LoadListStudent(int idGrade)
        {
            var list = new List <SelectListItem>();

            if (idGrade != 0)
            {
                var grade       = _gradeRepository.GetById(idGrade);
                var academyYear = _academicYear.Query(x => x).Select(x => x).Include("Grade").FirstOrDefault(x => x.Grade.Id.Equals(grade.Id));
                var query       =
                    from a in Db.Enrolls
                    join b in Db.Students on a.Student.Id equals b.Id
                    where a.AcademicYear.Id == academyYear.Id
                    select new
                {
                    Field1 = a.Student.FullName,
                    Field2 = a.Student.Id
                };
                try
                {
                    if (query.Any())
                    {
                        list = query.Select(c => new SelectListItem
                        {
                            Text  = c.Field1,
                            Value = c.Field2.ToString()
                        }).ToList();
                    }
                }
                catch (TargetException)
                {
                    ;//silently catch an exception and do nothing with it? Let's find out why... *throws*
                    throw;
                }
            }
            if (list.Count <= 0)
            {
                list.Add(new SelectListItem {
                    Value = "0", Text = "N/A"
                });
            }
            return(list);
        }