Example #1
0
        private IEnumerable GetListOpcionTypeNotification(string id)
        {
            var list = new List <SelectListItem>();

            //uh, no.
            switch (id)
            {
            case "1":
                list.Add(new SelectListItem {
                    Value = "0", Text = "N/A"
                });
                break;

            case "2":
                list = _areaReporsitory.Query(x => x).Select(c => new SelectListItem
                {
                    Text  = c.Name,
                    Value = c.Id.ToString()
                }).ToList();
                break;

            case "3":
                if (_sessionManagement.GetUserLoggedRole().Equals("Administrador"))
                {
                    list = _gradeRepository.Query(x => x).Select(c => new SelectListItem
                    {
                        Text  = c.Name,
                        Value = c.Id.ToString()
                    }).ToList();
                }
                else
                {
                    var email         = _sessionManagement.GetUserLoggedEmail();
                    var teacher       = _teacherRepository.FirstOrDefault(x => x.MyUser.Email.Equals(email));
                    var academicYears = _academicYearDetailRepository.GetAllAcademicYear(teacher.Id);
                    var gradesTeacherGiveClasssesTo = new List <Grade>();

                    foreach (
                        var year in academicYears.Where(year => !gradesTeacherGiveClasssesTo.Contains(year.Grade)))
                    {
                        gradesTeacherGiveClasssesTo.Add(year.Grade);
                    }

                    list = gradesTeacherGiveClasssesTo.Select(c => new SelectListItem
                    {
                        Text  = c.Name,
                        Value = c.Id.ToString()
                    }).ToList();
                }
                break;

            case "4":
                var user =
                    _userRepository.GetAllUsers()
                    .FirstOrDefault(x => x.Email == _sessionManagement.GetUserLoggedEmail());
                var listGrade = new List <Grade>();
                if (user != null)
                {
                    var people = _peopleRepository.GetAllPeopleByUserId(user.Id).FirstOrDefault(x => x is Teacher);
                    if (people != null)
                    {
                        var meiser = _teacherRepository.GetById(people.Id);
                        if (meiser != null)
                        {
                            var academyYear = _academicYearDetailRepository.GetAllAcademicYear(meiser.Id).ToList();

                            foreach (var year in academyYear.Where(year => !listGrade.Contains(year.Grade)))
                            {
                                listGrade.Add(year.Grade);
                            }
                        }
                        else
                        {
                            list = _gradeRepository.GetAllGrade().Select(c => new SelectListItem
                            {
                                Text  = c.Name,
                                Value = c.Id.ToString()
                            }).ToList();
                            break;
                        }
                    }
                    else
                    {
                        list = _gradeRepository.GetAllGrade().Select(c => new SelectListItem
                        {
                            Text  = c.Name,
                            Value = c.Id.ToString()
                        }).ToList();
                        break;
                    }
                }
                var allgrade = _gradeRepository.GetAllGrade().Select(x => x).ToList();
                var query    = from c in allgrade
                               join d in listGrade on c.Id equals d.Id
                               select new SelectListItem
                {
                    Text  = c.Name,
                    Value = d.Id.ToString()
                };
                list = query.ToList();
                break;
            }
            return(list);
        }