Exemple #1
0
        public async Task <IActionResult> Index()
        {
            if (!AuthUser.Identity.IsAuthenticated)
            {
                // not logged in, redirect to login page
                return(RedirectToRoute(new
                {
                    area = string.Empty,
                    controller = "SignIn",
                    ReturnUrl = "/MissionControl"
                }));
            }

            if (!UserHasPermission(Permission.AccessMissionControl))
            {
                // not authorized for Mission Control, redirect to authorization code

                return(RedirectToRoute(new
                {
                    area = "MissionControl",
                    controller = "Home",
                    action = "AuthorizationCode"
                }));
            }
            Site site = await GetCurrentSiteAsync();

            PageTitle = $"Mission Control: {site.Name}";

            // show the at-a-glance report
            int currentUserBranchId = GetId(ClaimType.BranchId);

            var siteStatus = await _reportService.GetCurrentStatsAsync(new ReportCriterion());

            var branchStatus = await _reportService.GetCurrentStatsAsync(new ReportCriterion
            {
                BranchId = currentUserBranchId
            });

            var branchName = await _siteService.GetBranchName(GetId(ClaimType.BranchId));

            return(View(new AtAGlanceViewModel
            {
                SiteStatus = siteStatus,
                FilteredBranchDescription = $"Your branch ({branchName})",
                FilteredStatus = branchStatus
            }));
        }
Exemple #2
0
        private async Task <AtAGlanceReport> GetAtAGlanceAsync()
        {
            int currentUserBranchId = GetId(ClaimType.BranchId);

            var siteStatus = await _reportService.GetCurrentStatsAsync(new ReportCriterion());

            var branchStatus = await _reportService.GetCurrentStatsAsync(new ReportCriterion
            {
                BranchId = currentUserBranchId
            });

            return(new AtAGlanceReport
            {
                FilteredBranchDescription = await _siteService.GetBranchName(currentUserBranchId),
                SiteStatus = siteStatus,
                FilteredStatus = branchStatus,
                LatestNewsId = await _newsService.GetLatestNewsIdAsync()
            });
        }
        public async Task <IActionResult> View(int id)
        {
            try
            {
                var storedReport = await _reportService.GetReportResultsAsync(id);

                PageTitle = storedReport.request.Name ?? "Report Results";

                var viewModel = new ReportResultsViewModel
                {
                    Title          = PageTitle,
                    ReportResultId = id
                };

                if (storedReport.criterion.StartDate.HasValue)
                {
                    viewModel.StartDate = storedReport.criterion.StartDate;
                }
                if (storedReport.criterion.EndDate.HasValue)
                {
                    viewModel.EndDate = storedReport.criterion.EndDate;
                }
                if (storedReport.criterion.SystemId.HasValue)
                {
                    viewModel.SystemName = (await _siteService
                                            .GetSystemByIdAsync(storedReport.criterion.SystemId.Value)).Name;
                }
                if (storedReport.criterion.BranchId.HasValue)
                {
                    viewModel.BranchName = await _siteService
                                           .GetBranchName(storedReport.criterion.BranchId.Value);
                }
                if (storedReport.criterion.ProgramId.HasValue)
                {
                    viewModel.ProgramName = (await _siteService
                                             .GetProgramByIdAsync(storedReport.criterion.ProgramId.Value)).Name;
                }
                if (storedReport.criterion.GroupInfoId.HasValue)
                {
                    viewModel.GroupName = (await _userService
                                           .GetGroupInfoByIdAsync(storedReport.criterion.GroupInfoId.Value)).Name;
                }
                if (storedReport.criterion.SchoolDistrictId.HasValue)
                {
                    viewModel.SchoolDistrictName = (await _schoolService
                                                    .GetDistrictByIdAsync(storedReport.criterion.SchoolDistrictId.Value)).Name;
                }
                if (storedReport.criterion.SchoolId.HasValue)
                {
                    viewModel.SchoolName = (await _schoolService
                                            .GetByIdAsync(storedReport.criterion.SchoolId.Value)).Name;
                }
                if (storedReport.criterion.VendorCodeTypeId.HasValue)
                {
                    viewModel.VendorCodeName = (await _vendorCodeService
                                                .GetTypeById(storedReport.criterion.VendorCodeTypeId.Value)).Description;
                }

                viewModel.ReportSet = JsonConvert
                                      .DeserializeObject <StoredReportSet>(storedReport.request.ResultJson);

                foreach (var report in viewModel.ReportSet.Reports)
                {
                    int count       = 0;
                    int totalRows   = report.Data.Count();
                    var displayRows = new List <List <string> >();

                    if (report.HeaderRow != null)
                    {
                        var display = new List <string>();
                        foreach (var dataItem in report.HeaderRow)
                        {
                            display.Add(FormatDataItem(dataItem));
                        }
                        report.HeaderRow = display;
                    }

                    foreach (var resultRow in report.Data)
                    {
                        var displayRow = new List <string>();

                        foreach (var resultItem in resultRow)
                        {
                            displayRow.Add(FormatDataItem(resultItem));
                        }
                        displayRows.Add(displayRow);
                        count++;
                    }
                    report.Data = displayRows;

                    if (report.FooterRow != null)
                    {
                        var display = new List <string>();
                        foreach (var dataItem in report.FooterRow)
                        {
                            display.Add(FormatDataItem(dataItem));
                        }
                        report.FooterRow = display;
                    }
                }

                return(View(viewModel));
            }
            catch (GraException gex)
            {
                AlertDanger = gex.Message;
                return(RedirectToAction("Index"));
            }
        }