/// <summary>
 /// Get a MDM contract using data in another entity
 /// </summary>
 /// <typeparam name="T">Type of the entity to use.</typeparam>
 /// <typeparam name="TContract">Type of the contract to use</typeparam>
 /// <param name="service">MDM service to use</param>
 /// <param name="entity">Entity to use</param>
 /// <param name="access">Function to return the identity of the contract from the entity.</param>
 /// <returns>MDM contract if found, otherwise null.</returns>
 public static TContract Get <T, TContract>(
     this IMdmModelEntityService service,
     T entity,
     Func <T, EntityId> access) where T : class, IMdmEntity where TContract : class, IMdmEntity
 {
     return(service.Get <TContract>(entity.ToMdmKey(access)));
 }
 public static TModel Model <T, TContract, TModel>(
     this IMdmModelEntityService service,
     T entity,
     Func <T, EntityId> access) where T : class, IMdmEntity where TContract : class, IMdmEntity
     where TModel : IMdmModelEntity <TContract>
 {
     return(service.Get <TContract, TModel>(service.Get <T, TContract>(entity, access)));
 }
        /// <summary>
        /// Try to execute a search, detecting if the service is available.
        /// </summary>
        /// <typeparam name="T">Type contained in the response.</typeparam>
        /// <param name="service">MDM service to use</param>
        /// <param name="search">Search to execute</param>
        /// <param name="results">Results of the search</param>
        /// <returns>true if the search worked, false otherwise.</returns>
        public static bool TrySearch <T>(this IMdmModelEntityService service, Search search, out IList <T> results)
            where T : IMdmEntity
        {
            var x = service.TrySearch <T>(search);

            results = x.Item2;
            return(x.Item1);
        }
        /// <summary>
        /// Try to execute a search, detecting if the service is available.
        /// </summary>
        /// <typeparam name="T">Type contained in the response.</typeparam>
        /// <typeparam name="TU">Target type, may be same as <see typeref="T" /></typeparam>
        /// <param name="service">MDM service to use</param>
        /// <param name="search">Search to execute</param>
        /// <param name="func">Function to transform the response into the target.</param>
        /// <param name="results">Results of the search</param>
        /// <returns>true if the search worked, false otherwise.</returns>
        public static bool TrySearch <T, TU>(this IMdmModelEntityService service, Search search, Func <T, TU> func, out IList <TU> results)
            where T : IMdmEntity
        {
            var x = service.TrySearch(search, func);

            results = x.Item2;
            return(x.Item1);
        }
        /// <summary>
        /// Try to execute a search, detecting if the service is available.
        /// </summary>
        /// <typeparam name="T">Type contained in the response.</typeparam>
        /// <param name="service">MDM service to use</param>
        /// <param name="search">Search to execute</param>
        /// <param name="version">optional version of contract to use in Search (default = 0)</param>
        /// <returns>true if the search worked, false otherwise.</returns>
        public static Tuple <bool, IList <T> > TrySearch <T>(this IMdmModelEntityService service, Search search, uint version = 0)
            where T : IMdmEntity
        {
            var response = service.Search <T>(search, version);

            return(response.Fault.IsServiceUnavailable()
                ? Tuple.Create(false, (IList <T>) new List <T>())
                : Tuple.Create(true, response.HandleResponse()));
        }
 public static PartyRole PartyRole <T>(this IMdmModelEntityService service, T entity, Func <T, EntityId> access)
     where T : class, IMdmEntity
 {
     return(service.Get <T, PartyRole>(entity, access));
 }
 public static PartyRole PartyRole(this IMdmModelEntityService service, int partyId)
 {
     return(service.Get <PartyRole>(partyId));
 }
 public static TModel Model <TContract, TModel>(this IMdmModelEntityService service, TContract entity)
     where TContract : class, IMdmEntity where TModel : IMdmModelEntity <TContract>
 {
     return(service.Get <TContract, TModel>(entity));
 }
 public static Location Location(this IMdmModelEntityService service, int locationId)
 {
     return(service.Get <Location>(locationId));
 }
 public static Exchange Exchange(this IMdmModelEntityService service, int exchangeId)
 {
     return(service.Get <Exchange>(exchangeId));
 }
 public static Broker Broker(this IMdmModelEntityService service, int brokerId)
 {
     return(service.Get <Broker>(brokerId));
 }