Base solution for your next web application
Open Closed

Session Parameter for Custom Data Filter #2428


User avatar
0
paymanrowhani created

Hi,

How can I automatically read custom data filter parameter value from AbpSession just like TenantId (as mentioned <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Filters">http://www.aspnetboilerplate.com/Pages/ ... ta-Filters</a>)? I don't want to use CurrentUnitOfWork.SetFilterParameter for every action.

Thanks, Payman

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Please see this example. <a class="postlink" href="https://gist.github.com/hikalkan/67469e05475c2d18cb88">https://gist.github.com/hikalkan/67469e05475c2d18cb88</a>

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    paymanrowhani created

    Hi,

    That did not meet my requirements. Suppose you have a dropdown listing years and you also have some entities implementing IHasYear (which has an int property Year). Then, by changing the value in dropdown, a Year is saved into session. Now, my question is, how to filter all subsequent queries for all controller actions based on the selected year without having to use CurrentUnitOfWork in each action. Please note that the Year can be changed after login. Would you please help?

    Thanks, Payman

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Override the Initialize method of your dbContext, call base's Initialize first and then add your parameter value like this. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs#L182">https://github.com/aspnetboilerplate/as ... xt.cs#L182</a>

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    paymanrowhani created

    Thank you so much!

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)