private IValidatable FindParentSection(FormSection section, int licenceId) { IValidatable parent; switch (section) { case FormSection.OrganisationDetails: parent = LicenceApplicationViewModelBuilder.Build <OrganisationDetailsViewModel>(licenceId) ?? new OrganisationDetailsViewModel(); break; case FormSection.PrincipalAuthority: parent = LicenceApplicationViewModelBuilder .Build <PrincipalAuthorityViewModel, PrincipalAuthority>( licenceId, l => l.PrincipalAuthorities.SingleOrDefault(p => p.Id == Session.GetCurrentPaId())); break; case FormSection.AlternativeBusinessRepresentative: parent = LicenceApplicationViewModelBuilder .Build <AlternativeBusinessRepresentativeViewModel, AlternativeBusinessRepresentative>( licenceId, l => l.AlternativeBusinessRepresentatives.SingleOrDefault(a => a.Id == Session.GetCurrentAbrId())); break; case FormSection.DirectorOrPartner: parent = LicenceApplicationViewModelBuilder.Build <DirectorOrPartnerViewModel, DirectorOrPartner>( licenceId, l => l.DirectorOrPartners.FirstOrDefault(d => d.Id == Session.GetCurrentDopId())); break; case FormSection.NamedIndividual: parent = LicenceApplicationViewModelBuilder.Build <NamedIndividualViewModel, NamedIndividual>( licenceId, l => l.NamedIndividuals.FirstOrDefault(n => n.Id == Session.GetCurrentNamedIndividualId())); break; case FormSection.Organisation: parent = LicenceApplicationViewModelBuilder.Build <OrganisationViewModel>(licenceId) ?? new OrganisationViewModel(); break; default: // Somehow we've saved a model without creating a parent parent = null; break; } return(parent); }