Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using this code to show user profile properties

XML
var currentUserId = User.Identity.GetUserId();
            var manager1 = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager1.FindById(User.Identity.GetUserId());
            TextBox1.Text = currentUser.UserInfo.FullName;


But how can update user profile properties below code is not working

XML
var currentUserId = User.Identity.GetUserId();
            var manager1 = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager1.FindById(User.Identity.GetUserId());
            currentUser.UserInfo.FullName = TextBox1.Text;
Posted

confusion arise from the fact that we create the UserManger in one line like this:


C#
var currentUserId = new UserManager<applicationuser>(new UserStore<applicationuser>(new MyDbContext()));</applicationuser></applicationuser>



SQL
then we use currentUserId .UpdateAsync( user ); but that will update the user in the context and then we will need to savechanges to the dbcontext of the Identity.. so the question is how to get the Identity DBcontext in the easiest way !!??

and to solve this we should not create the UserManger in one line ... and here is how I do it:



XML
var store = new UserStore<ApplicationUser>(new MyDbContext());
var currentUserId = new UserManager(store);


SQL
then after updating the user by calling currentUserId.UpdateAsync(user);

you go to the context as follow:


C#
var ctx = store.context;
then

ctx.saveChanges();
 
Share this answer
 
I just deleted this code and everything is working fine now thanks

C#
protected void Page_Load()
       {
           var currentUserId = User.Identity.GetUserId();
           var manager1 = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
           var currentUser = manager1.FindById(User.Identity.GetUserId());
           TextBox1.Text = currentUser.UserInfo.FullName;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900