Getting the Id is pretty straight forward and you've solved that.
Your second question though is a little more involved.
So, this is all prerelease stuff right now, but the common problem you're facing is where you're extending the user with new properties ( or an Items collection in you're question).
Out of the box you'll get a file called IdentityModel
under the Models folder (at the time of writing). In there you have a couple of classes; ApplicationUser
and ApplicationDbContext
. To add your collection of Items
you'll want to modify the ApplicationUser
class, just like you would if this were a normal class you were using with Entity Framework. In fact, if you take a quick look under the hood you'll find that all the identity related classes (User, Role etc...) are just POCOs now with the appropriate data annotations so they play nice with EF6.
Next, you'll need to make some changes to the AccountController
constructor so that it knows to use your DbContext.
public AccountController()
{
IdentityManager = new AuthenticationIdentityManager(
new IdentityStore(new ApplicationDbContext()));
}
Now getting the whole user object for your logged in user is a little esoteric to be honest.
var userWithItems = (ApplicationUser)await IdentityManager.Store.Users
.FindAsync(User.Identity.GetUserId(), CancellationToken.None);
That line will get the job done and you'll be able to access userWithItems.Items
like you want.
HTH
HttpContext.Current.User.Identity.Name
is the name of currently logged user. – Wiktor ZychlaItem
he creates, but not based on the username (that might change). It's not working by the way ` HttpContext.Current 'System.Web.HttpContextBase' does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument of type 'System.Web.HttpContextBase' could be found (are you missing a using directive or an assembly reference?)`. Are you sure your solution is for MVC 5? – Adam Szabo