0
私はエンティティを持っています:ItContractとすべてのItContractは組織単位に属しています。odataクエリのプロパティにフィルタを追加します
ユーザーは組織単位にログインし、すべてのデータに読み取りアクセス権を持ちます。 odataクエリごとにサーバー上のorganisationUnitIdにフィルタを設定するにはどうすればよいですか?
私はasp.netでodata v4を使用しています。
私はエンティティを持っています:ItContractとすべてのItContractは組織単位に属しています。odataクエリのプロパティにフィルタを追加します
ユーザーは組織単位にログインし、すべてのデータに読み取りアクセス権を持ちます。 odataクエリごとにサーバー上のorganisationUnitIdにフィルタを設定するにはどうすればよいですか?
私はasp.netでodata v4を使用しています。
サーバー側で取得したqueryOptionをオーバーライドする方法があります。
public IHttpActionResult Get(ODataQueryOptions<People> queryOptions)
{
// get the original request before the alterations
HttpRequestMessage originalRequest = queryOptions.Request;
// get the original URL before the alterations
string url = originalRequest.RequestUri.AbsoluteUri;
// rebuild the URL
if (queryOptions.Filter != null)
{
// apply the new filter
url = url.Replace("$filter=", "$filter=organisationUnitId%20eq%20" + organisationUnitId + ",");
}
else
{
if (url.Contains("$"))
{
url += "&";
}
url += "$filter=organisationUnitId%20eq%20" + organisationUnitId;
}
// build a new request for the filter
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, url);
// reset the query options with the new request
queryOptions = new ODataQueryOptions(queryOptions.Context, req);
var result = queryOptions.ApplyTo(_db.Prople);
return Ok(result, result.GetType());
}
private IHttpActionResult Ok(object content, Type type)
{
var resultType = typeof(OkNegotiatedContentResult<>).MakeGenericType(type);
return Activator.CreateInstance(resultType, content, this) as IHttpActionResult;
}