/// <summary> /// Map the supplied reference data organisation type to a common organisation type. /// This is always possible but both education and public bodies in the reference data world map to public bodies /// in the common types world. So once we've mapped one of these values from ref data we can not map them back. /// </summary> public static CommonOrganisationType ToCommonOrganisationType(this ReferenceDataOrganisationType organisationType) { switch (organisationType) { case ReferenceDataOrganisationType.Charity: return(CommonOrganisationType.Charities); case ReferenceDataOrganisationType.Company: return(CommonOrganisationType.CompaniesHouse); case ReferenceDataOrganisationType.EducationOrganisation: return(CommonOrganisationType.PublicBodies); case ReferenceDataOrganisationType.PublicSector: return(CommonOrganisationType.PublicBodies); default: return(CommonOrganisationType.Other); } }
/// <summary> /// Maps the supplied common organisation type to a reference data organisation type and returns false if this cannot be done. /// </summary> public static bool TryToReferenceDataOrganisationType(this CommonOrganisationType organisationType, out ReferenceDataOrganisationType referenceDataType) { switch (organisationType) { case CommonOrganisationType.Charities: referenceDataType = ReferenceDataOrganisationType.Charity; return(true); case CommonOrganisationType.CompaniesHouse: referenceDataType = ReferenceDataOrganisationType.Company; return(true); default: // We have to set the out param to something and there is no 'unknown' referenceDataType = ReferenceDataOrganisationType.Charity; return(false); } }
/// <summary> /// Returns true if the supplied reference data organisation type can be round-tripped to a common /// organisation type. /// </summary> /// <param name="organisationType"></param> /// <returns></returns> public static bool IsRoundTripCapable(this ReferenceDataOrganisationType organisationType) { var commonOrganisationType = organisationType.ToCommonOrganisationType(); return(commonOrganisationType.TryToReferenceDataOrganisationType(out _)); }