コード例 #1
0
        public IActionResult DownloadCompareData(int year = 0)
        {
            if (year == 0)
            {
                year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear();
            }

            var result    = CompareEmployers(year) as ViewResult;
            var viewModel = result.Model as CompareViewModel;
            IEnumerable <CompareReportModel> data = viewModel?.CompareReports;

            //Ensure we some data
            if (data == null || !data.Any())
            {
                return(new HttpNotFoundResult($"There is no employer data for year {year}"));
            }

            DataTable model = OrganisationBusinessLogic.GetCompareDatatable(data);

            //Setup the HTTP response
            var contentDisposition = new ContentDisposition {
                FileName = $"Compared GPG Data {ReportingYearsHelper.FormatYearAsReportingPeriod(year)}.csv", Inline = false
            };

            HttpContext.SetResponseHeader("Content-Disposition", contentDisposition.ToString());

            /* No Longer required as AspNetCore has response buffering on by default
             * Response.BufferOutput = true;
             */
            //Track the download
            WebTracker.TrackPageView(this, contentDisposition.FileName);

            //Return the data
            return(Content(model.ToCSV(), "text/csv"));
        }
コード例 #2
0
        public IActionResult SortEmployers(string column, string returnUrl)
        {
            //Check the parameters are populated
            if (string.IsNullOrWhiteSpace(column))
            {
                return(new HttpBadRequestResult($"Missing {nameof(column)}"));
            }

            //Check the parameters are populated
            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                return(new HttpBadRequestResult($"Missing {nameof(returnUrl)}"));
            }


            //Calculate the sort direction
            bool sort = CompareViewService.SortColumn != column || !CompareViewService.SortAscending;

            //Track the download
            if (CompareViewService.SortColumn != column || CompareViewService.SortAscending != sort)
            {
                WebTracker.TrackPageView(
                    this,
                    $"sort-employers: {column} {(CompareViewService.SortAscending ? "Ascending" : "Descending")}",
                    $"/compare-employers/sort-employers?{column}={(CompareViewService.SortAscending ? "Ascending" : "Descending")}");

                //Change the sort order
                CompareViewService.SortAscending = sort;

                //Set the column
                CompareViewService.SortColumn = column;
            }

            return(LocalRedirect(returnUrl));
        }
コード例 #3
0
        public IActionResult DownloadData(int year = 0)
        {
            if (year == 0)
            {
                year = SectorTypes.Private.GetAccountingStartDate().Year;
            }

            string filePath     = Path.Combine(Global.DownloadsLocation, $"GPGData_{year}-{year + 1}.csv");
            string fileContents = fileRepository.Read(filePath);

            string userFacingDownloadFileName = $"UK Gender Pay Gap Data - {year} to {year + 1}.csv";

            //Track the download
            WebTracker.TrackPageView(this, userFacingDownloadFileName);

            return(DownloadHelper.CreateCsvDownload(fileContents, userFacingDownloadFileName));
        }
コード例 #4
0
        public IActionResult CompareEmployers(int year, string employers = null)
        {
            if (year == 0)
            {
                CompareViewService.SortColumn    = null;
                CompareViewService.SortAscending = true;
                year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear();
            }

            //Load employers from querystring (via shared email)
            if (!string.IsNullOrWhiteSpace(employers))
            {
                string[] comparedEmployers = employers.SplitI("-");
                if (comparedEmployers.Any())
                {
                    CompareViewService.ClearBasket();
                    CompareViewService.AddRangeToBasket(comparedEmployers);
                    CompareViewService.SortAscending = true;
                    CompareViewService.SortColumn    = null;
                    return(RedirectToAction("CompareEmployers", new { year }));
                }
            }

            //If the session is lost then load employers from the cookie
            else if (CompareViewService.BasketItemCount == 0)
            {
                CompareViewService.LoadComparedEmployersFromCookie();
            }

            ViewBag.ReturnUrl = Url.Action("CompareEmployers", new { year });

            //Clear the default back url of the employer hub pages
            EmployerBackUrl = null;
            ReportBackUrl   = null;

            //Get the compare basket organisations
            IEnumerable <CompareReportModel> compareReports = OrganisationBusinessLogic.GetCompareData(
                CompareViewService.ComparedEmployers.Value.AsEnumerable(),
                year,
                CompareViewService.SortColumn,
                CompareViewService.SortAscending);

            //Track the compared employers
            string lastComparedEmployerList = CompareViewService.ComparedEmployers.Value.ToList().ToSortedSet().ToDelimitedString();

            if (CompareViewService.LastComparedEmployerList != lastComparedEmployerList && IsAction("CompareEmployers"))
            {
                SortedSet <string> employerIds = compareReports.Select(r => r.EncOrganisationId).ToSortedSet();
                WebTracker.TrackPageView(
                    this,
                    $"compare-employers: {employerIds.ToDelimitedString()}",
                    $"{ViewBag.ReturnUrl}?{employerIds.ToEncapsulatedString("e=", null, "&", "&", false)}");
                foreach (CompareReportModel employer in compareReports)
                {
                    WebTracker.TrackPageView(
                        this,
                        $"{employer.EncOrganisationId}: {employer.OrganisationName}",
                        $"{ViewBag.ReturnUrl}?{employer.EncOrganisationId}={employer.OrganisationName}");
                }

                CompareViewService.LastComparedEmployerList = lastComparedEmployerList;
            }

            //Generate the shared links
            string shareEmailUrl = Url.Action(
                nameof(CompareEmployers),
                "Compare",
                new { year, employers = CompareViewService.ComparedEmployers.Value.ToList().ToDelimitedString("-") },
                Request.Scheme);

            ViewBag.BasketViewModel = new CompareBasketViewModel {
                CanAddEmployers = true, CanViewCompare = false, CanClearCompare = true
            };

            return(View(
                       "CompareEmployers",
                       new CompareViewModel {
                LastSearchUrl = SearchViewService.GetLastSearchUrl(),
                CompareReports = compareReports,
                CompareBasketCount = CompareViewService.BasketItemCount,
                ShareEmailUrl =
                    CompareViewService.BasketItemCount <= CompareViewService.MaxCompareBasketShareCount ? shareEmailUrl : null,
                Year = year,
                SortAscending = CompareViewService.SortAscending,
                SortColumn = CompareViewService.SortColumn
            }));
        }
コード例 #5
0
        public IActionResult Redirect()
        {
            WebTracker.TrackPageView(this);

            return(RedirectToAction("EnterCalculations"));
        }