2016-08-18 38 views
1

我已经添加了一些属性,我的应用程序的用户类别,就像下面:如何更新/编辑asp.net标识中的用户个人资料信息EF代码第一种方法?

public class ApplicationUser : IdentityUser 
    { 
     public string Name { get; set; } 

     public string LastName { get; set; } 

     public DateTime? DOB { get; set; } 
     public string Gender { get; set; } 
     public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) 
     { 
      // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
      var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 
      // Add custom user claims here 
      return userIdentity; 
     } 
    } 

而且我在RegisterViewModel相应增加这些属性,并相应地更新Register视图。一切都运行超级好,我可以添加用户添加这些自定义属性。 问题是如何在用户创建帐户后更新/编辑用户配置文件数据,包括(姓名,姓氏,出生日期等)。 我知道我必须有一个ActionResult方法,但坦率地说,我不太了解它。 Regards

回答

0

在一个操作方法中,只需使用您的数据上下文来检索,更新和/或保存模型。

using (var ctx = new MyDataContext()) 
{ 
    var person = ctx.ApplicationUsers.FirstOrDefault(); 
    person.Name = "Johnny"; 
    person.LastName = "Depp"; 

    ctx.SaveChanges();     
} 
相关问题