private void SaveChangesToDraftReturn(ReportHourlyPayViewModel viewModel, long organisationId, int reportingYear) { DraftReturn draftReturn = draftReturnService.GetOrCreateDraftReturn(organisationId, reportingYear); draftReturn.DiffMeanHourlyPayPercent = viewModel.DiffMeanHourlyPayPercent; draftReturn.DiffMedianHourlyPercent = viewModel.DiffMedianHourlyPercent; draftReturnService.SaveDraftReturnOrDeleteIfNotRelevent(draftReturn); }
private void PopulateViewModel(ReportHourlyPayViewModel viewModel, long organisationId, int reportingYear) { Organisation organisation = dataRepository.Get <Organisation>(organisationId); viewModel.Organisation = organisation; viewModel.ReportingYear = reportingYear; Return submittedReturn = organisation.GetReturn(reportingYear); bool isEditingSubmittedReturn = submittedReturn != null; viewModel.IsEditingSubmittedReturn = isEditingSubmittedReturn; }
public IActionResult ReportHourlyPayGet(string encryptedOrganisationId, int reportingYear) { ControllerHelper.Throw404IfFeatureDisabled(FeatureFlag.NewReportingJourney); long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); var viewModel = new ReportHourlyPayViewModel(); PopulateViewModel(viewModel, organisationId, reportingYear); SetFigures(viewModel, organisationId, reportingYear); return(View("ReportHourlyPay", viewModel)); }
private void SetFigures(ReportHourlyPayViewModel viewModel, long organisationId, int reportingYear) { DraftReturn draftReturn = draftReturnService.GetDraftReturn(organisationId, reportingYear); if (draftReturn != null) { SetFiguresFromDraftReturn(viewModel, draftReturn); return; } Return submittedReturn = viewModel.Organisation.GetReturn(reportingYear); if (submittedReturn != null) { SetFiguresFromSubmittedReturn(viewModel, submittedReturn); return; } }
public IActionResult ReportHourlyPayPost(string encryptedOrganisationId, int reportingYear, ReportHourlyPayViewModel viewModel) { ControllerHelper.Throw404IfFeatureDisabled(FeatureFlag.NewReportingJourney); long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); ValidateUserInput(viewModel); if (viewModel.HasAnyErrors()) { PopulateViewModel(viewModel, organisationId, reportingYear); return(View("ReportHourlyPay", viewModel)); } SaveChangesToDraftReturn(viewModel, organisationId, reportingYear); string nextPageUrl = viewModel.Action == ReportPagesAction.Save ? Url.Action("ReportHourlyPayGet", "ReportHourlyPay", new { encryptedOrganisationId = encryptedOrganisationId, reportingYear = reportingYear }) : Url.Action("ReportOverview", "ReportOverview", new { encryptedOrganisationId = encryptedOrganisationId, reportingYear = reportingYear }); StatusMessageHelper.SetStatusMessage(Response, "Saved changes to hourly pay", nextPageUrl); return(LocalRedirect(nextPageUrl)); }
private void SetFiguresFromSubmittedReturn(ReportHourlyPayViewModel viewModel, Return submittedReturn) { viewModel.DiffMeanHourlyPayPercent = submittedReturn.DiffMeanHourlyPayPercent; viewModel.DiffMedianHourlyPercent = submittedReturn.DiffMedianHourlyPercent; }
private void SetFiguresFromDraftReturn(ReportHourlyPayViewModel viewModel, DraftReturn draftReturn) { viewModel.DiffMeanHourlyPayPercent = draftReturn.DiffMeanHourlyPayPercent; viewModel.DiffMedianHourlyPercent = draftReturn.DiffMedianHourlyPercent; }
private void ValidateUserInput(ReportHourlyPayViewModel viewModel) { viewModel.ParseAndValidateParameters(Request, m => m.DiffMeanHourlyPayPercent); viewModel.ParseAndValidateParameters(Request, m => m.DiffMedianHourlyPercent); }