/// <summary> /// Synchronously gets a single <see cref="IGroup">Group</see> from a query. /// </summary> /// <param name="parent">The parent resource that contains a link to a <see cref="ITenant">Tenant</see>.</param> /// <param name="queryAction">The query.</param> /// <returns>The located <see cref="IGroup">Group</see>.</returns> private static IGroup GetSingleTenantGroup( IHasTenant parent, Func <IQueryable <IGroup>, IQueryable <IGroup> > queryAction) { if (queryAction == null) { throw new ArgumentNullException(nameof(queryAction)); } var tenant = parent.GetTenant(); var queryable = tenant.GetGroups().Synchronously(); queryable = queryAction(queryable); IGroup foundGroup = null; foreach (var group in queryable) { if (foundGroup != null) { throw new ArgumentException("The provided query matched more than one Directory in the current Tenant.", nameof(queryAction)); } foundGroup = group; } return(foundGroup); }
/// <summary> /// Synchronously gets a single <see cref="IDirectory">Directory</see> from a query. /// </summary> /// <param name="parent">The parent resource that contains a link to a <see cref="ITenant">Tenant</see>.</param> /// <param name="queryAction">The query.</param> /// <returns>The located <see cref="IDirectory">Directory</see>.</returns> private static IDirectory GetSingleTenantDirectory( IHasTenant parent, Func <IQueryable <IDirectory>, IQueryable <IDirectory> > queryAction) { if (queryAction == null) { throw new ArgumentNullException(nameof(queryAction)); } var tenant = parent.GetTenant(); var queryable = tenant.GetDirectories().Synchronously(); queryable = queryAction(queryable); IDirectory foundDirectory = null; foreach (var dir in queryable) { if (foundDirectory != null) { throw new ArgumentException("The provided query matched more than one Directory in the current Tenant.", nameof(queryAction)); } foundDirectory = dir; } return(foundDirectory); }