public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new Bookstore.Models.User { UserName = model.Username, Firstname = model.Firstname, Lastname = model.Lastname, Email = model.Email }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(View(model)); }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<BookstoreContext, Configuration>()); using (BookstoreContext context = new BookstoreContext()) { var user = new User(); user.Username = "******"; user.AuthCode = "0123456789012345678901234567890123456789"; context.Users.Add(user); context.SaveChanges(); } }