public IActionResult ManageOrganisationGet(string encryptedOrganisationId) { // Check for feature flag and redirect if not enabled if (!FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.NewManageOrganisationsJourney)) { return(RedirectToAction("ManageOrganisationGet", "ManageOrganisations", new { encryptedOrganisationId = encryptedOrganisationId })); } long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); User user = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(user); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); var organisation = dataRepository.Get <Organisation>(organisationId); if (OrganisationIsNewThisYearAndHasNotProvidedScopeForLastYear(organisation)) { return(RedirectToAction("DeclareScope", "Organisation", new { id = encryptedOrganisationId })); } // build the view model List <int> yearsWithDraftReturns = dataRepository.GetAll <DraftReturn>() .Where(d => d.OrganisationId == organisationId) .Select(d => d.SnapshotYear) .ToList(); var viewModel = new ManageOrganisationViewModel(organisation, user, yearsWithDraftReturns); return(View("ManageOrganisation", viewModel)); }
public IActionResult ManageOrganisationGet(string encryptedOrganisationId) { long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); User user = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(user); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); var organisation = dataRepository.Get <Organisation>(organisationId); if (OrganisationIsNewThisYearAndHasNotProvidedScopeForLastYear(organisation)) { return(RedirectToAction("DeclareScope", "Organisation", new { id = encryptedOrganisationId })); } // build the view model List <DraftReturn> allDraftReturns = dataRepository.GetAll <DraftReturn>() .Where(d => d.OrganisationId == organisationId) .ToList(); var viewModel = new ManageOrganisationViewModel(organisation, user, allDraftReturns); return(View("ManageOrganisation", viewModel)); }