public ActionResult Create(UsuarioViewModel model, params string[] selectedRoles) { if (ModelState.IsValid) { Usuario user = new Usuario { UserName = model.Nome, Email = model.Email }; IdentityResult result = GerenciadorUsuario.Create(user, model.Senha); if (result.Succeeded) { //Adiciona o usuário à(s) regra(s) selecionada(s) if (selectedRoles != null) { var resultado = GerenciadorUsuario.AddToRoles(user.Id, selectedRoles); if (!resultado.Succeeded) { AddErrorsFromResult(resultado); return(View()); } } return(RedirectToAction("Index")); } else { AddErrorsFromResult(result); return(View()); } } return(View()); }
public ActionResult Create(UsuarioViewModel model) { if (ModelState.IsValid) { Usuario user = new Usuario { UserName = model.Nome, Email = model.Email }; IdentityResult result = GerenciadorUsuario.Create(user, model.Senha); if (result.Succeeded) { return(RedirectToAction("Index")); } else { AddErrorsFromResult(result); } } return(View(model)); }