public async Task <IActionResult> DeclareScope(string id) { //Ensure user has completed the registration process var checkResult = await CheckUserRegisteredOkAsync(); if (checkResult != null) { return(checkResult); } // Decrypt org id if (!id.DecryptToId(out var organisationId)) { return(new HttpBadRequestResult($"Cannot decrypt organisation id {id}")); } // Check the user has permission for this organisation var userOrg = VirtualUser.UserOrganisations.FirstOrDefault(uo => uo.OrganisationId == organisationId); if (userOrg == null) { return(new HttpForbiddenResult( $"User {VirtualUser?.EmailAddress} is not registered for organisation id {organisationId}")); } // Ensure this user is registered fully for this organisation if (userOrg.PINConfirmedDate == null) { return(new HttpForbiddenResult( $"User {VirtualUser?.EmailAddress} has not completed registration for organisation {userOrg.Organisation.EmployerReference}")); } //Get the current snapshot date var snapshotDate = SharedBusinessLogic.GetAccountingStartDate(userOrg.Organisation.SectorType).AddYears(-1); if (snapshotDate.Year < SharedBusinessLogic.SharedOptions.FirstReportingYear) { return(new HttpBadRequestResult($"Snapshot year {snapshotDate.Year} is invalid")); } var scopeStatus = await SubmissionService.ScopeBusinessLogic.GetLatestScopeStatusForSnapshotYearAsync(organisationId, snapshotDate.Year); if (scopeStatus.IsAny(ScopeStatuses.InScope, ScopeStatuses.OutOfScope)) { return(new HttpBadRequestResult("Explicit scope is already set")); } // build the view model var model = new DeclareScopeModel { OrganisationName = userOrg.Organisation.OrganisationName, SnapshotDate = snapshotDate }; return(View(model)); }
public static ISharedBusinessLogic CreateFakeSharedBusinessLogic() { var mockedSnapshotDateHelper = new Mock <ISnapshotDateHelper>(); var mockedSourceComparer = new Mock <ISourceComparer>(); var mockedSendEmailService = new Mock <ISendEmailService>(); var mockedNotificationService = new Mock <INotificationService>(); var mockedFileRepository = new Mock <IFileRepository>(); var mockedDataRepository = new Mock <IDataRepository>(); var mockSharedBusinessLogic = new SharedBusinessLogic(mockedSnapshotDateHelper.Object, mockedSourceComparer.Object, mockedSendEmailService.Object, mockedNotificationService.Object, mockedFileRepository.Object, mockedDataRepository.Object); return(mockSharedBusinessLogic); }
public void BeforeEach() { // setup mocks mockDataRepository = MoqHelpers.CreateMockDataRepository(); var mockedSnapshotDateHelper = Get <ISnapshotDateHelper>(); var mockedSourceComparer = Get <ISourceComparer>(); var mockedSendEmailService = Get <ISendEmailService>(); var mockedNotificationService = Get <INotificationService>(); var mockedFileRepository = Get <IFileRepository>(); var mockedDataRepository = Get <IDataRepository>(); mockSharedBusinessLogic = new SharedBusinessLogic(mockedSnapshotDateHelper, mockedSourceComparer, mockedSendEmailService, mockedNotificationService, mockedFileRepository, mockedDataRepository); // sut scopeBusinessLogic = new Submission.ScopeBusinessLogic( mockSharedBusinessLogic, mockDataRepository.Object, null, null); }
public void BeforeEach() { // setup mocks mockDataRepository = MoqHelpers.CreateMockDataRepository(); var mockedSnapshotDateHelper = Get <ISnapshotDateHelper>(); var mockedSourceComparer = Get <ISourceComparer>(); var mockedSendEmailService = Get <ISendEmailService>(); var mockedNotificationService = Get <INotificationService>(); var mockedFileRepository = Get <IFileRepository>(); var mockedDataRepository = Get <IDataRepository>(); mockSharedBusinessLogic = new SharedBusinessLogic(mockedSnapshotDateHelper, mockedSourceComparer, mockedSendEmailService, mockedNotificationService, mockedFileRepository, mockedDataRepository); // setup data var currentPrivateSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(SectorTypes.Private); var currentPublicSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(SectorTypes.Public); testOrgs = new List <Organisation>(); testOrgs.Add(CreateOrgWithExistingScopeForAllYears(1, SectorTypes.Private, currentPrivateSnapshotDate)); testOrgs.Add(CreateOrgWithExistingScopeForAllYears(2, SectorTypes.Public, currentPublicSnapshotDate)); testOrgs.Add(CreateOrgWithMissingScopesForAllYears(3, SectorTypes.Private)); testOrgs.Add(CreateOrgWithMissingScopesForAllYears(4, SectorTypes.Public)); testOrgs.Add(CreateOrgWithUnknownScopesForAllYears(5, SectorTypes.Private, currentPrivateSnapshotDate)); testOrgs.Add(CreateOrgWithUnknownScopesForAllYears(6, SectorTypes.Public, currentPublicSnapshotDate)); mockDataRepository.SetupGetAll(testOrgs); // sut scopeBusinessLogic = new Submission.ScopeBusinessLogic( mockSharedBusinessLogic, mockDataRepository.Object, null, null); }
public async Task <IActionResult> ManageOrganisation(string id) { //Ensure user has completed the registration process var checkResult = await CheckUserRegisteredOkAsync(); if (checkResult != null) { return(checkResult); } // Decrypt org id if (!id.DecryptToId(out var organisationId)) { return(new HttpBadRequestResult($"Cannot decrypt organisation id {id}")); } // Check the user has permission for this organisation var userOrg = VirtualUser.UserOrganisations.FirstOrDefault(uo => uo.OrganisationId == organisationId); if (userOrg == null) { return(new HttpForbiddenResult( $"User {VirtualUser?.EmailAddress} is not registered for organisation id {organisationId}")); } // clear the stash ClearStash(); //Get the current snapshot date var currentSnapshotDate = SharedBusinessLogic.GetAccountingStartDate(userOrg.Organisation.SectorType); //Make sure we have an explicit scope for last and year for organisations new to this year if (userOrg.PINConfirmedDate != null && userOrg.Organisation.Created >= currentSnapshotDate) { var scopeStatus = await _SubmissionService.ScopeBusinessLogic.GetLatestScopeStatusForSnapshotYearAsync(organisationId, currentSnapshotDate.Year - 1); if (!scopeStatus.IsAny(ScopeStatuses.InScope, ScopeStatuses.OutOfScope)) { return(RedirectToAction(nameof(ScopeController.DeclareScope), "Scope", new { id })); } } // get any associated users for the current org var associatedUserOrgs = userOrg.GetAssociatedUsers().ToList(); // get all editable reports var reportInfos = await _SubmissionPresenter.GetAllEditableReportsAsync(userOrg, currentSnapshotDate); // build the view model var model = new ManageOrganisationModel { CurrentUserOrg = userOrg, AssociatedUserOrgs = associatedUserOrgs, EncCurrentOrgId = Encryption.EncryptQuerystring(organisationId.ToString()), ReportInfoModels = reportInfos.OrderBy(r => r.ReportingStartDate).ToList() }; return(View(model)); }