Open Closed

How to use IMustHaveCreator implementation to an app service #7916


User avatar
0
hakanyanaz@gmail.com created

Check the samples to see the basic tasks: https://abp.io/docs/latest/samples

The exact solution to your question may have been answered before, and please first use the search on the homepage.

Provide us with the following info:

🧐 Hint: If you are using the ABP Studio, you can see all the information about your solution from the configuration window, which opens when you right-click on the solution and click on the Solution Configuration button.

ABP Framework version: v8.3.0

UI Type:MVC

Database System: EF Core (SQL Server)

Tiered (for MVC) or Auth Server Separated (for Angular): no

Exception message and full stack trace:

Steps to reproduce the issue:

Hi,

A solution is created by using ABP Suite and upgraded to V8.3.0 via ABP Suite user interface.

Product entity is created.

2 user is created and assigned to registereduser role.

user1 is created a record into the Product entity via auto-generated page in .Web app.

It is needed to filter the records based on CreatorId .

A service method is created in the ProductsAppService.Extended.cs as follows :

    public async Task<List<Product>> GetMyProductListAsync()
    {
        using (_dataFilter.Enable<IMustHaveCreator>())
        {
            return await _productRepository.GetListAsync();            
        }
    }

I couldn't find an appropriate usage of this implementation.

I will be very appreciated if anyone has a sample code or any advice.

Thanks


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can try:

    ... IRepository<Product, Guid> _productRepository;
    
    public async Task<List<Product>> GetMyProductListAsync()
    {
        using (_dataFilter.Enable<IMustHaveCreator>())
        {
            return await _productRepository.GetListAsync(x => x.CreatorId == CurrentUser.Id);            
        }
    }
    
  • User Avatar
    0
    hakanyanaz@gmail.com created

    Thank you for a quick reply. If a parameter is used, data filtering doesn't affect to the result that means there is no need to use data filter implementation. Maybe I couldn't understand very well the use-cases of this concept. Does it effective only for dbcontext level?

    You can try:

    ... IRepository<Product, Guid> _productRepository; 
     
    public async Task<List<Product>> GetMyProductListAsync() 
    { 
        using (_dataFilter.Enable<IMustHaveCreator>()) 
        { 
            return await _productRepository.GetListAsync(x => x.CreatorId == CurrentUser.Id);             
        } 
    } 
    

    <br>

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Basically you can ignore it, It is designed for audit purposes

Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13