// GET: Admin
        public ActionResult Index()
        {
            var model = new AdminIndexViewModel
            {
                AppUserSession = _appUserService.GetSession(),
                FocusedEdOrg   = _edOrgService.GetEdOrgById(_appUserService.GetSession().FocusedEdOrgId,
                                                            _schoolYearService.GetSchoolYearById(_appUserService.GetSession().FocusedSchoolYearId).Id),
                YearsOpenForDataSubmission =
                    _schoolYearService.GetSubmittableSchoolYears().OrderByDescending(x => x.EndYear),
                RuleCollections  = _rulesEngineService.GetCollections(),
                SubmissionCycles = _submissionCycleService.GetSubmissionCycles(),
                Announcements    = _announcementService.GetAnnouncements()
            };

            // Check user authorization, if user is admin then then return admin page if not return the error page.
            return(model.AppUserSession.UserIdentity.GetViewPermissions(model.AppUserSession.UserIdentity.AppRole).CanAccessAdminFeatures
                       ? View(model)
                       : View("Error"));
        }
Пример #2
0
        // GET: Admin
        public ActionResult Index()
        {
            var schoolYears = _schoolYearService.GetSubmittableSchoolYears();

            var viewsPerYear = new Dictionary <int, IEnumerable <ValidationRulesView> >();

            foreach (var schoolYear in schoolYears)
            {
                viewsPerYear.Add(
                    schoolYear.Id,
                    _dynamicReportingService.GetRulesViews(schoolYear.Id));
            }

            var model = new AdminIndexViewModel
            {
                AppUserSession = _appUserService.GetSession(),
                FocusedEdOrg   = _edOrgService.GetEdOrgById(
                    _appUserService.GetSession().FocusedEdOrgId,
                    _schoolYearService.GetSchoolYearById(_appUserService.GetSession().FocusedSchoolYearId).Id),
                YearsOpenForDataSubmission = schoolYears.OrderByDescending(x => x.EndYear),
                RuleCollections            = _rulesEngineService.GetCollections(),
                SubmissionCycles           = _submissionCycleService.GetSubmissionCycles(),
                Announcements             = _announcementService.GetAnnouncements(),
                RulesViewsPerSchoolYearId = viewsPerYear,
                ReportSchoolYearId        = _appUserService.GetSession().FocusedSchoolYearId
            };

            PopulateDropDownLists();

            // Check user authorization, if user is admin then then return admin page if not redirect to home.
            if (model
                .AppUserSession
                .UserIdentity.GetViewPermissions(model.AppUserSession.UserIdentity.AppRole)
                .CanAccessAdminFeatures)
            {
                return(View(model));
            }

            return(RedirectToAction("Index", "Home"));
        }