Beispiel #1
0
        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));
        }
Beispiel #2
0
        public IActionResult ManageOrganisation(string id)
        {
            // Check for feature flag and redirect if enabled
            if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.NewManageOrganisationsJourney))
            {
                return(RedirectToAction("ManageOrganisationGet", "ManageOrganisations", new { encryptedOrganisationId = id }));
            }

            //Ensure user has completed the registration process
            IActionResult checkResult = CheckUserRegisteredOk(out User currentUser);

            if (checkResult != null)
            {
                return(checkResult);
            }

            // Decrypt org id
            if (!id.DecryptToId(out long organisationId))
            {
                return(new HttpBadRequestResult($"Cannot decrypt organisation id {id}"));
            }

            // Check the user has permission for this organisation
            UserOrganisation userOrg = currentUser.UserOrganisations.FirstOrDefault(uo => uo.OrganisationId == organisationId);

            if (userOrg == null || userOrg.PINConfirmedDate == null)
            {
                return(new HttpForbiddenResult($"User {currentUser?.EmailAddress} is not registered for organisation id {organisationId}"));
            }

            // clear the stash
            this.ClearStash();

            //Get the current snapshot date
            DateTime currentSnapshotDate = userOrg.Organisation.SectorType.GetAccountingStartDate();

            //Make sure we have an explicit scope for last and year for organisations new to this year
            if (userOrg.HasBeenActivated() && userOrg.Organisation.Created >= currentSnapshotDate)
            {
                ScopeStatuses scopeStatus =
                    ScopeBusinessLogic.GetLatestScopeStatusForSnapshotYear(organisationId, currentSnapshotDate.Year - 1);
                if (!scopeStatus.IsAny(ScopeStatuses.InScope, ScopeStatuses.OutOfScope))
                {
                    return(RedirectToAction(nameof(DeclareScope), "Organisation", new { id }));
                }
            }

            // get any associated users for the current org
            List <UserOrganisation> associatedUserOrgs = userOrg.GetAssociatedUsers().ToList();

            // build the view model
            List <int> yearsWithDraftReturns =
                DataRepository.GetAll <DraftReturn>()
                .Where(d => d.OrganisationId == organisationId)
                .Select(d => d.SnapshotYear)
                .ToList();

            var model = new ManageOrganisationModel {
                CurrentUserOrg                 = userOrg,
                AssociatedUserOrgs             = associatedUserOrgs,
                EncCurrentOrgId                = Encryption.EncryptQuerystring(organisationId.ToString()),
                ReportingYearsWithDraftReturns = yearsWithDraftReturns
            };

            return(View(model));
        }