Added a new field to RegisterViewModel
:
[Required]
[Display(Name = "Name ")]
public string Name { get; set; }
Added in AccountController
:
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
Name = model.Name
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
Now I want create a migration file, using command
add-migration newFieldName
VS generates the file, but it is empty.
public partial class newFieldName : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
Update: ApplicationUser
class
public class ApplicationUser : IdentityUser
{
[Required]
public string Name { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}