2

I'm trying to create an application where I'm using Windows Identity and Entity Framework Code First. So I'm creating a custom class to save some data.

public class Order {
  public string Name { get; set; }
  public DateTime CreatedDate { get; set; }
  public IdentityUser User { get; set; }
}

Now I'm trying to link the user table to the order table (as generated by Entity Framework). So that I can do Order.User to get user info on the user who created the Order.

I want to create a new order using

new Order {
  Name = "Test",
  CreatedDate = new DateTime(2014, 3, 30),
  User = <What goes here?>
}

Now how to I get "IdentityUser" of the currently logged in user? Or am I going about this the wrong way?

Daniel Olsen
  • 1,020
  • 2
  • 15
  • 27

1 Answers1

5

You can get the current user from User.Identity inside of a controller, and HttpContext.Current.User.Identity from outside. Check this: ASP.NET MVC 5 - Identity. How to get current ApplicationUser

Community
  • 1
  • 1
Peter Hurtony
  • 472
  • 3
  • 17
  • Thank you very much. Could you tell me the difference between an "ApplicationUser" and an "IdentityUser" - Cause I thought I needed the IdentityUser class? – Daniel Olsen Mar 31 '14 at 19:39
  • 1
    IdentityUser is the base class of ApplicationUser. You can extend the base user entity in this way. You can also create for example an ApplicationRole from IdentityRole etc – Peter Hurtony Mar 31 '14 at 23:32