Skip to content

Commit

Permalink
EHD-1051: Compare page: Update Compare page URLs to use old the same …
Browse files Browse the repository at this point in the history
…URLs as the old page
  • Loading branch information
jamesgriff committed Oct 15, 2024
1 parent cafef12 commit 6a6320b
Showing 1 changed file with 170 additions and 170 deletions.
340 changes: 170 additions & 170 deletions GenderPayGap.WebUI/Controllers/CompareEmployersController.cs
Original file line number Diff line number Diff line change
@@ -1,171 +1,171 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using GenderPayGap.Core;
using GenderPayGap.Core.Classes;
using GenderPayGap.Core.Helpers;
using GenderPayGap.Core.Interfaces;
using GenderPayGap.Database;
using GenderPayGap.Extensions;
using GenderPayGap.WebUI.Classes.Presentation;
using GenderPayGap.WebUI.Helpers;
using GenderPayGap.WebUI.Models.Compare;
using Microsoft.AspNetCore.Mvc;

namespace GenderPayGap.WebUI.Controllers
{
public class CompareEmployersController : Controller
{

private readonly ICompareViewService compareViewService;
private readonly IDataRepository dataRepository;

public CompareEmployersController(
ICompareViewService compareViewService,
IDataRepository dataRepository)
{
this.compareViewService = compareViewService;
this.dataRepository = dataRepository;
}

[HttpGet("/compare-employers-2")]
public IActionResult CompareEmployersNoYear(string employers = null)
{
int year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear();
RedirectToActionResult action = !string.IsNullOrWhiteSpace(employers)
? RedirectToAction("CompareEmployersForYear", new {year = year, employers = employers})
: RedirectToAction("CompareEmployersForYear", new {year = year});
return action;
}

[HttpGet("/compare-employers-2/{year}")]
public IActionResult CompareEmployersForYear(int year, string employers = null)
{
compareViewService.LoadComparedEmployersFromCookie();

ControllerHelper.ThrowIfReportingYearIsOutsideOfRangeForAnyOrganisation(year);
var viewModel = new CompareEmployersForYearViewModel
{
ReportingYear = year
};

List<string> encodedEmployerIds;
if (!string.IsNullOrWhiteSpace(employers))
{
encodedEmployerIds = employers.Split("-", StringSplitOptions.RemoveEmptyEntries).ToList();
viewModel.CameFromShareLink = true;
}
else
{
encodedEmployerIds = compareViewService.ComparedEmployers;
viewModel.CameFromShareLink = false;
}

// Hopefully we can remove this step one day!
List<long> organisationIds = DecodeOrganisationIds(encodedEmployerIds);

foreach (long organisationId in organisationIds)
{
try
{
Organisation organisation = dataRepository.Get<Organisation>(organisationId);
viewModel.Organisations.Add(organisation);
}
catch (Exception e)
{}
}

return View("CompareEmployersForYear", viewModel);
}

[HttpGet("/compare-employers-2/{year}/download-csv")]
public IActionResult DownloadCSVOfCompareEmployersForYear(int year, string employers = null)
{
compareViewService.LoadComparedEmployersFromCookie();

ControllerHelper.ThrowIfReportingYearIsOutsideOfRangeForAnyOrganisation(year);

List<string> encodedEmployerIds;
if (!string.IsNullOrWhiteSpace(employers))
{
encodedEmployerIds = employers.Split("-", StringSplitOptions.RemoveEmptyEntries).ToList();
}
else
{
encodedEmployerIds = compareViewService.ComparedEmployers;
}

// Hopefully we can remove this step one day!
List<long> organisationIds = DecodeOrganisationIds(encodedEmployerIds);
var organisationsToDownload = new List<Organisation>();

foreach (long organisationId in organisationIds)
{
try
{
Organisation organisation = dataRepository.Get<Organisation>(organisationId);
organisationsToDownload.Add(organisation);
}
catch (Exception e)
{}
}

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using GenderPayGap.Core;
using GenderPayGap.Core.Classes;
using GenderPayGap.Core.Helpers;
using GenderPayGap.Core.Interfaces;
using GenderPayGap.Database;
using GenderPayGap.Extensions;
using GenderPayGap.WebUI.Classes.Presentation;
using GenderPayGap.WebUI.Helpers;
using GenderPayGap.WebUI.Models.Compare;
using Microsoft.AspNetCore.Mvc;

namespace GenderPayGap.WebUI.Controllers
{
public class CompareEmployersController : Controller
{

private readonly ICompareViewService compareViewService;
private readonly IDataRepository dataRepository;

public CompareEmployersController(
ICompareViewService compareViewService,
IDataRepository dataRepository)
{
this.compareViewService = compareViewService;
this.dataRepository = dataRepository;
}

[HttpGet("/compare-employers")]
public IActionResult CompareEmployersNoYear(string employers = null)
{
int year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear();
RedirectToActionResult action = !string.IsNullOrWhiteSpace(employers)
? RedirectToAction("CompareEmployersForYear", new {year = year, employers = employers})
: RedirectToAction("CompareEmployersForYear", new {year = year});
return action;
}

[HttpGet("/compare-employers/{year}")]
public IActionResult CompareEmployersForYear(int year, string employers = null)
{
compareViewService.LoadComparedEmployersFromCookie();

ControllerHelper.ThrowIfReportingYearIsOutsideOfRangeForAnyOrganisation(year);
var viewModel = new CompareEmployersForYearViewModel
{
ReportingYear = year
};

List<string> encodedEmployerIds;
if (!string.IsNullOrWhiteSpace(employers))
{
encodedEmployerIds = employers.Split("-", StringSplitOptions.RemoveEmptyEntries).ToList();
viewModel.CameFromShareLink = true;
}
else
{
encodedEmployerIds = compareViewService.ComparedEmployers;
viewModel.CameFromShareLink = false;
}

// Hopefully we can remove this step one day!
List<long> organisationIds = DecodeOrganisationIds(encodedEmployerIds);

foreach (long organisationId in organisationIds)
{
try
{
Organisation organisation = dataRepository.Get<Organisation>(organisationId);
viewModel.Organisations.Add(organisation);
}
catch (Exception e)
{}
}

return View("CompareEmployersForYear", viewModel);
}

[HttpGet("/compare-employers/{year}/download-csv")]
public IActionResult DownloadCSVOfCompareEmployersForYear(int year, string employers = null)
{
compareViewService.LoadComparedEmployersFromCookie();

ControllerHelper.ThrowIfReportingYearIsOutsideOfRangeForAnyOrganisation(year);

List<string> encodedEmployerIds;
if (!string.IsNullOrWhiteSpace(employers))
{
encodedEmployerIds = employers.Split("-", StringSplitOptions.RemoveEmptyEntries).ToList();
}
else
{
encodedEmployerIds = compareViewService.ComparedEmployers;
}

// Hopefully we can remove this step one day!
List<long> organisationIds = DecodeOrganisationIds(encodedEmployerIds);
var organisationsToDownload = new List<Organisation>();

foreach (long organisationId in organisationIds)
{
try
{
Organisation organisation = dataRepository.Get<Organisation>(organisationId);
organisationsToDownload.Add(organisation);
}
catch (Exception e)
{}
}

var records = organisationsToDownload.OrderBy(org => org.OrganisationName).Select(
organisation =>
{
Return returnForYear = organisation.GetReturn(year);
bool hasEmployerReportedForYear = returnForYear != null;
ReportStatusTag reportStatusTag = ReportStatusTagHelper.GetReportStatusTag(organisation, year);

return new
{
EmployerName = organisation.OrganisationName,
ReportStatus = reportStatusTag.ToString(),
NumberOfEmployees = hasEmployerReportedForYear ? returnForYear.OrganisationSize.GetAttribute<DisplayAttribute>().Name : "",

GenderPayGap_HourlyPay_Mean_Percent = hasEmployerReportedForYear ? returnForYear.DiffMeanHourlyPayPercent.ToString() : "",
GenderPayGap_HourlyPay_Median_Percent = hasEmployerReportedForYear ? returnForYear.DiffMedianHourlyPercent.ToString() : "",

WomenInEachPayQuarter_Lower_Percent = hasEmployerReportedForYear ? returnForYear.FemaleLowerPayBand.ToString() : "",
WomenInEachPayQuarter_LowerMiddle_Percent = hasEmployerReportedForYear ? returnForYear.FemaleMiddlePayBand.ToString() : "",
WomenInEachPayQuarter_UpperMiddle_Percent = hasEmployerReportedForYear ? returnForYear.FemaleUpperPayBand.ToString() : "",
WomenInEachPayQuarter_Upper_Percent = hasEmployerReportedForYear ? returnForYear.FemaleUpperQuartilePayBand.ToString() : "",

WhoReceivesBonusPay_Women_Percent = hasEmployerReportedForYear ? returnForYear.FemaleMedianBonusPayPercent.ToString( ): "",
WhoReceivesBonusPay_Men_Percent = hasEmployerReportedForYear ? returnForYear.MaleMedianBonusPayPercent.ToString( ): "",

GenderPayGap_BonusPay_Mean_Percent = hasEmployerReportedForYear && returnForYear.DiffMeanBonusPercent.HasValue
? returnForYear.DiffMeanBonusPercent.Value.ToString()
: "",
GenderPayGap_BonusPay_Median_Percent = hasEmployerReportedForYear && returnForYear.DiffMedianBonusPercent.HasValue
? returnForYear.DiffMedianBonusPercent.Value.ToString()
: "",
};
})
.ToList();

string fileDownloadName = $"UK Gender Pay Gap Data for selected employers {ReportingYearsHelper.FormatYearAsReportingPeriod(year)}.csv";
return DownloadHelper.CreateCsvDownload(records, fileDownloadName);
}

private List<long> DecodeOrganisationIds(List<string> encodedEmployerIds)
{
var organisationIds = new List<long>();

foreach (string encodedEmployerId in encodedEmployerIds)
{
try
{
long organisationId = Obfuscator.DeObfuscate(encodedEmployerId);
organisationIds.Add(organisationId);
}
catch (Exception e)
{}
}
return organisationIds;
}

}
}
organisation =>
{
Return returnForYear = organisation.GetReturn(year);
bool hasEmployerReportedForYear = returnForYear != null;
ReportStatusTag reportStatusTag = ReportStatusTagHelper.GetReportStatusTag(organisation, year);

return new
{
EmployerName = organisation.OrganisationName,
ReportStatus = reportStatusTag.ToString(),
NumberOfEmployees = hasEmployerReportedForYear ? returnForYear.OrganisationSize.GetAttribute<DisplayAttribute>().Name : "",

GenderPayGap_HourlyPay_Mean_Percent = hasEmployerReportedForYear ? returnForYear.DiffMeanHourlyPayPercent.ToString() : "",
GenderPayGap_HourlyPay_Median_Percent = hasEmployerReportedForYear ? returnForYear.DiffMedianHourlyPercent.ToString() : "",

WomenInEachPayQuarter_Lower_Percent = hasEmployerReportedForYear ? returnForYear.FemaleLowerPayBand.ToString() : "",
WomenInEachPayQuarter_LowerMiddle_Percent = hasEmployerReportedForYear ? returnForYear.FemaleMiddlePayBand.ToString() : "",
WomenInEachPayQuarter_UpperMiddle_Percent = hasEmployerReportedForYear ? returnForYear.FemaleUpperPayBand.ToString() : "",
WomenInEachPayQuarter_Upper_Percent = hasEmployerReportedForYear ? returnForYear.FemaleUpperQuartilePayBand.ToString() : "",

WhoReceivesBonusPay_Women_Percent = hasEmployerReportedForYear ? returnForYear.FemaleMedianBonusPayPercent.ToString( ): "",
WhoReceivesBonusPay_Men_Percent = hasEmployerReportedForYear ? returnForYear.MaleMedianBonusPayPercent.ToString( ): "",

GenderPayGap_BonusPay_Mean_Percent = hasEmployerReportedForYear && returnForYear.DiffMeanBonusPercent.HasValue
? returnForYear.DiffMeanBonusPercent.Value.ToString()
: "",
GenderPayGap_BonusPay_Median_Percent = hasEmployerReportedForYear && returnForYear.DiffMedianBonusPercent.HasValue
? returnForYear.DiffMedianBonusPercent.Value.ToString()
: "",
};
})
.ToList();

string fileDownloadName = $"UK Gender Pay Gap Data for selected employers {ReportingYearsHelper.FormatYearAsReportingPeriod(year)}.csv";
return DownloadHelper.CreateCsvDownload(records, fileDownloadName);
}

private List<long> DecodeOrganisationIds(List<string> encodedEmployerIds)
{
var organisationIds = new List<long>();

foreach (string encodedEmployerId in encodedEmployerIds)
{
try
{
long organisationId = Obfuscator.DeObfuscate(encodedEmployerId);
organisationIds.Add(organisationId);
}
catch (Exception e)
{}
}
return organisationIds;
}

}
}

0 comments on commit 6a6320b

Please sign in to comment.