How to relate your entities has already been answered, but there is another way to do this without relating them:
When your user logs in you create a UserList class with the aspNetUserId property and write to an authCookie. So every time you need the User Id you read the cookie and fill in the UserList object. It's another way to do this, I'm not saying it's the best ...
In your Login:
if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
if (result.Succeeded)
{
var usuario = await _userManager.FindByEmailAsync(model.Email);
var usuarioLogado = new UsuarioLogado
{
AspNetUserId = usuario.Id,
// outros dados que quiser
};
//cria cookie de autenticação
_httpContext.SetAuthCookie(_dataProtectionProvider, model.RememberMe, usuarioLogado);
But then how do I read the cookie?
The least repetitive way is to create a controller to do this for you:
public class BaseController : Controller
{
private readonly IDataProtectionProvider _dataProtectionProvider;
public BaseController(IDataProtectionProvider dataProtectionProvider)
{
_dataProtectionProvider = dataProtectionProvider;
}
public UsuarioLogado UsuarioLogado { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
try
{
base.OnActionExecuting(filterContext);
}
catch (System.Exception e)
{
throw;
}
var httpContext = Request.HttpContext;
try {
var usuario = httpContext.GetAuthCookieData<UsuarioLogado>(_dataProtectionProvider);
UsuarioLogado = usuario;
}
catch (System.Exception e) {
httpContext.Response.Redirect("~/Account/?erro=1");
}
}
}
And then when you need to use the logged-in user on your controller, you make the controller inherit from the baseController:
[Route("api/Teste")]
public class ApiTesteController : BaseController
{
// aqui você pode chamar: UsuarioLogado.AspNetUserId
NOTE: You want to report, so you lose the relationship and use (virtual) browsing properties but you can easily query and bring in the data you want. If you are using entityFramework:
var proprietarios = (context ou repositorio de proprietario).Where(x => x.UsuarioId == (usuario logado ou qualquer outro));