public IActionResult RemoveConviction(UnspentConvictionViewModel model, FormSection section, int id)
        {
            LicenceApplicationPostDataHandler.Delete <Conviction>(id);

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }
        public IActionResult AddConviction(UnspentConvictionViewModel model, FormSection section, int id)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("AddConviction", new { section, id }));
            }

            switch (section)
            {
            case FormSection.PrincipalAuthority:
            {
                var answerId = LicenceApplicationPostDataHandler
                               .UpsertSecurityAnswerAndLinkToParent <UnspentConvictionViewModel, Conviction, PrincipalAuthority>(
                    Session.GetCurrentPaId(), id, model, pa => pa.UnspentConvictions, uc => uc.PrincipalAuthority);

                if (Session.GetCurrentPaIsDirector())
                {
                    LicenceApplicationPostDataHandler
                    .UpsertSecurityAnswerAndLinkToParent <UnspentConvictionViewModel, Conviction, DirectorOrPartner>(
                        Session.GetCurrentDopId(), answerId, model, dop => dop.UnspentConvictions,
                        uc => uc.DirectorOrPartner);
                }
                break;
            }

            case FormSection.AlternativeBusinessRepresentative:
                LicenceApplicationPostDataHandler
                .UpsertSecurityAnswerAndLinkToParent <UnspentConvictionViewModel, Conviction,
                                                      AlternativeBusinessRepresentative>(
                    Session.GetCurrentAbrId(), id, model, abr => abr.UnspentConvictions,
                    uc => uc.AlternativeBusinessRepresentative);
                break;

            case FormSection.DirectorOrPartner:
            {
                var answerId = LicenceApplicationPostDataHandler
                               .UpsertSecurityAnswerAndLinkToParent <UnspentConvictionViewModel, Conviction, DirectorOrPartner>(
                    Session.GetCurrentDopId(), id, model, dop => dop.UnspentConvictions, uc => uc.DirectorOrPartner);

                if (Session.GetCurrentDopIsPa())
                {
                    LicenceApplicationPostDataHandler
                    .UpsertSecurityAnswerAndLinkToParent <UnspentConvictionViewModel, Conviction, PrincipalAuthority>(
                        Session.GetCurrentPaId(), answerId, model, pa => pa.UnspentConvictions,
                        uc => uc.PrincipalAuthority);
                }
                break;
            }

            case FormSection.NamedIndividual:
                LicenceApplicationPostDataHandler
                .UpsertSecurityAnswerAndLinkToParent <UnspentConvictionViewModel, Conviction,
                                                      NamedIndividual>(
                    Session.GetCurrentNamedIndividualId(), id, model, ni => ni.UnspentConvictions,
                    uc => uc.NamedIndividual);
                break;
            }

            var lastLoaded = Session.GetLoadedPage();

            return(RedirectToAction(section, lastLoaded));
        }