2

I would validate if the currenlty active user has permission to acces the company. Below I have two samples of GET and PUT request, to fetch company details and to updated company details. Is it possible to write a Data Annotation so I can point, or send a property to it so I'm able to validate if the user can access it?

Sample:

[ValidateCompanyPermission("companyId")]
[HttpGet]
public async Task<IActionResult> GetCompany(long companyId)
{
    
}

public class CompanyRequest
{
    public long UpdatedById { get; set; }
    public string NewCompanyName
}

[ValidateCompanyPermission("UserRequest.UpdatedById")]
[HttpPut]
public async Task<IActionResult> GetCompanz(CompanyRequest companyRequest)
{
    
}
sharp
  • 1,191
  • 14
  • 39

1 Answers1

0

If sending parameters to the attribute logic is what you want, it's not possible. I quote vcsjones in the same question answered here

Attributes are meta data. Parameter values must be a constant value.

Jim
  • 86
  • 3