📅  最后修改于: 2022-03-11 14:49:18.745000             🧑  作者: Mango
public async Task Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
//Assign Role to User
await this.UserManager.AddToRoleAsync(user.Id, model.UserRoles);
return RedirectToAction("Index", "Home");
}
ViewBag.Name = new SelectList(context.Roles.Where(u => !u.Name.Contains("Admin"))
.ToList(), "Name", "Name");
AddErrors(result);
}
// Register Student