I am beyond confused regarding user authentication in asp.net MVC5... I've been referring this article:
And this questions:
MVC 5 Custom UserStore ASP.net Identity - How does UserManager<TUser> Have Access To Roles?
...and getting absolutely know where. Here is the code in my IdentityModel.cs
namespace attempt_4.Models
{
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
}
public class MyUserStore : IUserStore<ApplicationUser>
{
}
public class ApplicationDbContext<ApplicationUser> : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
}
And in the controller I'm attempting to get the UserObject with:
var userManager = new UserManager<ApplicationUser>(new MyUserStore<ApplicationUser>(new ApplicationDbContext()));
var user = userManager.FindById(User.Identity.GetUserId());
This gives me a plethora of compile errors most in the form of attempt_4.Models.MyUserStore<ApplicationUser>' does not implement interface member 'System.IDisposable.Dispose(), but also one saying ApplicationUser cannot be used as Type parameter 'TUser'.
At the moment I'm using:
var id = User.Identity.GetUserId();
var user = db.Users.First(x => x.Id == id);
This can't be the best way, no doubt the db was already queried due to the [Authorize].
I don't need anything involving roles or anything fancy... just want to extend the User model and be able to reference it from other models to do stuff like this: db.Apartments.where(apt => apt.OwnerId == currentUserID). That said, what is the best practice for linking tables to the User table? Should I have a int id in the ApplicationUser class to query by? Or should I just use the Guid?