public async Task <ActionResult> Approved(string hashedAccountId, string hashedCommitmentId)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var model = await Orchestrator.GetAcknowledgementModelForExistingCommitment(
                hashedAccountId,
                hashedCommitmentId,
                OwinWrapper.GetClaimValue(@"sub"));

            var currentStatusCohortAny = await Orchestrator
                                         .AnyCohortsForCurrentStatus(hashedAccountId, RequestStatus.ReadyForApproval);

            model.Data.BackLink = currentStatusCohortAny
                ? new LinkViewModel {
                Text = "Return to view cohorts", Url = Url.Action("ReadyForReview", new { hashedAccountId })
            }
                : new LinkViewModel {
                Text = "Return to Your cohorts", Url = Url.Action("YourCohorts", new { hashedAccountId })
            };

            return(View(model));
        }
        public async Task <ActionResult> AcknowledgementExisting(string hashedAccountId, string hashedCommitmentId, SaveStatus saveStatus)
        {
            if (!await IsUserRoleAuthorized(hashedAccountId, Role.Owner, Role.Transactor))
            {
                return(View("AccessDenied"));
            }

            var response = await Orchestrator
                           .GetAcknowledgementModelForExistingCommitment(hashedAccountId, hashedCommitmentId, OwinWrapper.GetClaimValue(@"sub"));

            var  status = GetRequestStatusFromCookie();
            bool anyCohortsLeft;

            if (status == RequestStatus.ReadyForReview)
            {
                anyCohortsLeft = await Orchestrator.AnyCohortsForCurrentStatus(hashedAccountId, RequestStatus.ReadyForApproval, status);
            }
            else
            {
                anyCohortsLeft = await Orchestrator.AnyCohortsForCurrentStatus(hashedAccountId, status);
            }
            var returnToCohortsList =
                status != RequestStatus.None &&
                anyCohortsLeft;

            var returnUrl = GetReturnUrl(status, hashedAccountId);

            response.Data.BackLink = string.IsNullOrEmpty(returnUrl) || !returnToCohortsList
                ? new LinkViewModel {
                Url = Url.Action("YourCohorts", new { hashedAccountId }), Text = "Return to Your cohorts"
            }
                : new LinkViewModel {
                Url = returnUrl, Text = "Go back to view cohorts"
            };

            response.Data.Content = GetAcknowledgementContent(saveStatus, response.Data.IsTransfer);

            return(View("Acknowledgement", response));
        }
        public async Task <ActionResult> DeleteCohort(DeleteCommitmentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var model = await Orchestrator
                            .GetDeleteCommitmentModel(viewModel.HashedAccountId, viewModel.HashedCommitmentId, OwinWrapper.GetClaimValue(@"sub"));

                return(View(model));
            }

            if (viewModel.DeleteConfirmed == null || !viewModel.DeleteConfirmed.Value)
            {
                return(Redirect(_linkGenerator.CommitmentsV2Link($"{viewModel.HashedAccountId}/unapproved/{viewModel.HashedCommitmentId}")));
            }

            await Orchestrator
            .DeleteCommitment(viewModel.HashedAccountId, viewModel.HashedCommitmentId, OwinWrapper.GetClaimValue("sub"), OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName), OwinWrapper.GetClaimValue(DasClaimTypes.Email));

            var flashmessage = new FlashMessageViewModel
            {
                Message  = "Records deleted",
                Severity = FlashMessageSeverityLevel.Okay
            };

            AddFlashMessageToCookie(flashmessage);

            var anyCohortWithCurrentStatus =
                await Orchestrator.AnyCohortsForCurrentStatus(viewModel.HashedAccountId, GetRequestStatusFromCookie());

            if (!anyCohortWithCurrentStatus)
            {
                return(RedirectToAction("YourCohorts", new { viewModel.HashedAccountId }));
            }

            return(Redirect(GetReturnToListUrl(viewModel.HashedAccountId)));
        }