Esempio n. 1
0
        public ActionResult Add()
        {
            var user       = _userRepository.GetById(Convert.ToInt64(_sessionManagementService.GetUserLoggedId()));
            var isDirector = ViewBag.IsDirector = user.Role.Name.Equals("Director");

            if (isDirector)
            {
                var firstOrDefault = _educationLevelRepository.Filter(x => x.Director != null && x.Director.Id == user.Id)
                                     .FirstOrDefault();
                if (firstOrDefault != null)
                {
                    return(View("Create", new GradeRegisterModel {
                        EducationLevel = firstOrDefault.Id
                    }));
                }
            }
            var list = _educationLevelRepository.GetAllAreas();

            ViewBag.EducationLevels = new SelectList(list, "Id", "Name");
            return(View("Create"));
        }
        public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            var listaArea = _areaReposity.GetAllAreas();

            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            if (!String.IsNullOrEmpty(searchString))
            {
                listaArea = _areaReposity.Filter(x => x.Name.Contains(searchString)).ToList();
            }
            var listaAreaDisplaysModel = listaArea.Select(Mapper.Map <EducationLevel, DisplayEducationLevelModel>).ToList();

            ViewBag.CurrentFilter = searchString;
            switch (sortOrder)
            {
            case "name_desc":
                listaAreaDisplaysModel = listaAreaDisplaysModel.OrderByDescending(s => s.Name).ToList();
                break;

            default:      // Name ascending
                listaAreaDisplaysModel = listaAreaDisplaysModel.OrderBy(s => s.Name).ToList();
                break;
            }
            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);

            return(View(listaAreaDisplaysModel.ToPagedList(pageNumber, pageSize)));
        }
        private NotificationSelectListsModel LoadEducationLevels(NotificationRegisterModel model, NotificationSelectListsModel toReturn)
        {
            var user =
                _userRepository.GetById(Convert.ToInt64(_sessionManagement.GetUserLoggedId()));
            var isDirector = user.Role.Name.Equals("Director");

            toReturn.EducationLevels = new SelectList(isDirector ? _areaReporsitory.Filter(x => x.Director != null && x.Director.Id == user.Id) : _areaReporsitory.GetAllAreas(), "Id", "Name");
            return(toReturn);
        }