public async Task <IActionResult> Create(CustomerViewModel model) { if (ModelState.IsValid) { Customer customer = new Customer { FirstName = model.FirstName, LastName = model.LastName, StreetName = model.StreetName, City = model.City, Parish = model.Parish, Country = model.Country, userEmail = model.userEmail, userPassword = model.userPassword, userConfirmedPassword = model.userConfirmedPassword, AccountNumber = model.AccountNumber, CardNumber = model.CardNumber, AccountType = model.AccountType, Balance = model.Balance }; var user = new AppUser { UserName = model.userEmail, Email = model.userEmail, userFirstName = model.FirstName, userLastName = model.LastName, userStreetName = model.StreetName, userCity = model.City, userParish = model.Parish, userCountry = model.Country }; var result = await userManager.CreateAsync(user, model.userPassword); if (result.Succeeded) { //Add user role to user await userManager.AddToRoleAsync(user, "Customer"); _context.Add(customer); await _context.SaveChangesAsync(); if (signInManager.IsSignedIn(User) && User.IsInRole("Admin")) { return(RedirectToAction("Index", "Customers")); } //await signInManager.SignInAsync(user, isPersistent: false); //return RedirectToAction("index", "home"); return(RedirectToAction("Index", "Customers")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View()); }
public async Task <IActionResult> Create(CustomerViewModel model) { Teller teller = new Teller { FirstName = model.FirstName, LastName = model.LastName, userEmail = model.userEmail, userPassword = model.userPassword, userConfirmedPassword = model.userConfirmedPassword }; var user = new AppUser { UserName = model.userEmail, Email = model.userEmail, userFirstName = model.FirstName, userLastName = model.LastName }; var result = await userManager.CreateAsync(user, model.userPassword); if (result.Succeeded) { //Add user role to user await userManager.AddToRoleAsync(user, "Teller"); _context.Add(teller); await _context.SaveChangesAsync(); if (signInManager.IsSignedIn(User) && User.IsInRole("Admin")) { return(RedirectToAction("ListRoles", "Admin")); } //await signInManager.SignInAsync(user, isPersistent: false); //return RedirectToAction("index", "home"); return(RedirectToAction("ListRoles", "Admin")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View(teller)); }