public IActionResult SaveIsPreviousPrincipalAuthority(IsPreviousPrincipalAuthorityViewModel model)
        {
            Session.SetSubmittedPage(FormSection.DirectorOrPartner, 1);

            if (!ModelState.IsValid || !model.IsPreviousPrincipalAuthority.HasValue)
            {
                return(View(GetViewPath(FormSection.DirectorOrPartner, 1), model));
            }

            var dopId = LicenceApplicationPostDataHandler.Update(Session.GetCurrentLicenceId(), l => l.DirectorOrPartners, model,
                                                                 Session.GetCurrentDopId());

            Session.SetCurrentDopStatus(dopId, model.IsPreviousPrincipalAuthority.Value);

            if (model.IsPreviousPrincipalAuthority.Value)
            {
                var paId = LicenceApplicationPostDataHandler.UpsertPrincipalAuthorityAndLinkToDirectorOrPartner(
                    Session.GetCurrentLicenceId(), dopId, Session.GetCurrentPaId(), model);
                Session.SetCurrentPaStatus(paId, true);
            }
            else
            {
                LicenceApplicationPostDataHandler.UnlinkPrincipalAuthorityFromDirectorOrPartner(Session.GetCurrentDopId());
            }

            return(CheckParentValidityAndRedirect(FormSection.DirectorOrPartner, 1));
        }
Exemplo n.º 2
0
        public void it_unlinks_the_principal_authority_from_a_director()
        {
            const int dopId = 1;
            var       dop   = new DirectorOrPartner {
                Id = dopId, PrincipalAuthority = new PrincipalAuthority()
            };

            repository.GetById <DirectorOrPartner>(dopId).Returns(dop);

            var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider);

            pdh.UnlinkPrincipalAuthorityFromDirectorOrPartner(dopId);

            repository.Received(1).Upsert(Arg.Is <DirectorOrPartner>(d => d.PrincipalAuthority == null));
        }