public async Task <ActionResult> Sign(string agreementId, string hashedAccountId, int?choice)
        {
            var userInfo = OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName);

            if (choice == null)
            {
                var agreement = await GetSignedAgreementViewModel(new GetEmployerAgreementRequest { AgreementId = agreementId, HashedAccountId = hashedAccountId, ExternalUserId = userInfo });

                ModelState.AddModelError(nameof(agreement.Choice), "Select whether you accept the agreement");

                return(View(ControllerConstants.SignAgreementViewName, agreement));
            }

            if (choice == SignEmployerAgreementViewModel.ReviewAgreementLater)
            {
                return(RedirectToAction(ControllerConstants.IndexActionName, ControllerConstants.EmployerTeamControllerName));
            }

            var response = await _orchestrator.SignAgreement(agreementId, hashedAccountId, userInfo, DateTime.UtcNow);

            if (response.Status == HttpStatusCode.Unauthorized)
            {
                return(View(response));
            }

            var user = await _mediator.SendAsync(new GetUserByRefQuery { UserRef = userInfo });

            if (!string.IsNullOrWhiteSpace(user.User.CorrelationId))
            {
                var getProviderInvitationQueryResponse = await _mediator.SendAsync(new GetProviderInvitationQuery
                {
                    CorrelationId = Guid.Parse(user.User.CorrelationId)
                });

                if (getProviderInvitationQueryResponse.Result?.Status < InvitationComplete)
                {
                    return(Redirect(@Url.ProviderRelationshipsAction($"providers/invitation/{user.User.CorrelationId}")));
                }
            }


            if (response.Status == HttpStatusCode.OK)
            {
                ViewBag.CompanyName = response.Data.LegalEntityName;
                ViewBag.HasFurtherPendingAgreements = response.Data.HasFurtherPendingAgreements;
                return(View(ControllerConstants.AcceptedEmployerAgreementViewName));
            }

            return(RedirectToAction(ControllerConstants.SignAgreementActionName, new GetEmployerAgreementRequest {
                AgreementId = agreementId, ExternalUserId = userInfo, HashedAccountId = hashedAccountId
            }));
        }
        public async Task <ActionResult> Sign(string agreementId, string hashedAccountId)
        {
            var userInfo  = OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName);
            var agreement = await _orchestrator.GetById(agreementId, hashedAccountId, userInfo);

            var response = await _orchestrator.SignAgreement(agreementId, hashedAccountId, userInfo, DateTime.UtcNow,
                                                             agreement.Data.EmployerAgreement.LegalEntityName);

            if (response.Status == HttpStatusCode.OK)
            {
                FlashMessageViewModel flashMessage = new FlashMessageViewModel
                {
                    Headline = "Agreement signed",
                    Severity = FlashMessageSeverityLevel.Success
                };

                ActionResult result;

                if (response.Data.HasFurtherPendingAgreements)
                {
                    flashMessage.Message =
                        "You've successfully signed an organisation agreement. There are outstanding agreements to be signed. Review the list below to sign all remaining agreements.";

                    result = RedirectToAction(ControllerConstants.IndexActionName,
                                              ControllerConstants.EmployerAgreementControllerName,
                                              new { hashedAccountId, agreementSigned = true });
                }
                else
                {
                    flashMessage.Headline = "All agreements signed";
                    flashMessage.Message  = "You've successfully signed all of your organisation agreements.";
                    result = RedirectToAction(ControllerConstants.NextStepsActionName);
                }

                AddFlashMessageToCookie(flashMessage);

                return(result);
            }


            agreement.Exception = response.Exception;
            agreement.Status    = response.Status;

            return(View(ControllerConstants.SignAgreementViewName, agreement.Data));
        }
        public async Task <ActionResult> Sign(string agreementId, string hashedAccountId)
        {
            var response = await _orchestrator.SignAgreement(agreementId, hashedAccountId, OwinWrapper.GetClaimValue(@"sub"), DateTime.UtcNow);

            if (response.Status == HttpStatusCode.OK)
            {
                var flashMessage = new FlashMessageViewModel
                {
                    Headline = "Agreement signed",
                    Severity = FlashMessageSeverityLevel.Success
                };
                AddFlashMessageToCookie(flashMessage);

                return(RedirectToAction("Index", new { hashedAccountId }));
            }

            var agreement = await _orchestrator.GetById(agreementId, hashedAccountId, OwinWrapper.GetClaimValue(@"sub"));

            agreement.Exception = response.Exception;
            agreement.Status    = response.Status;

            return(View("SignAgreement", agreement));
        }