Say I have these classes:
public class User
{
public int? Id { get; set; }
...
}
public class Wallet
{
public int? Id { get; set; }
public string Title {get; set;}
public User Owner { get; set; }
...
}
public class WalletCreationDTO
{
[Required]
public string Title {get; set;}
[Required]
public int OwnerId { get; set; }
}
[HttpPost]
public async Task<ActionResult> CreateWallet(WalletCreationDto walletDTO) {...}
I must report any erroneous parameters to the frontend like so:
{
"errors": {
"ownerId": "User by Id does not exist",
"title": "Must not exceed 8 characters"
}
}
How do I go about validating the OwnerId?
- Manually querying the database seems ineffective
- The default ASP.NET Core validation doesn't seem to have any annotations related to database access