Implement OrganizationUnit filter in ASP.NET Core

大城市里の小女人 提交于 2019-12-04 19:38:03

This isn't just a few lines of code.

Start with how IMayHaveTenant is filtered in CreateFilterExpression.

You can override ShouldFilterEntity and CreateFilterExpression in your DbContext.

SetTenantId is used to configure the tenantId, how could I configure OrganizationUnitId from UnitOfWork?

You can use the equivalent SetFilterParameter method.

But, it always return value from OrganizationUnitId in CustomAbpSession, this method CurrentUnitOfWork.SetFilterParameter did not set the value into filter.

From CurrentUnitOfWorkProvider.Current, you can access Filters:

protected virtual long? GetCurrentOrganizationUnitIdOrNull()
{
    if (CurrentUnitOfWorkProvider != null &&
        CurrentUnitOfWorkProvider.Current != null)
    {
        return CurrentUnitOfWorkProvider.Current
            .Filters.FirstOrDefault(f => f.FilterName == "MayHaveOrganizationUnit")?
            .FilterParameters["OrganizationUnitId"] as long?;
    }

    return ((ICustomAbpSession)AbpSession).OrganizationUnitId;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!