public async Task <ActionResult> RegistrarRole(FuncaoRegistro funcaoRegistro) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } var role = new IdentityRole { Name = funcaoRegistro.FuncaoNome }; var result = await _roleManager.CreateAsync(role); if (result.Succeeded) { var funcao = Funcao.ObterEnumIdPeloNome(funcaoRegistro.FuncaoNome); } foreach (var error in result.Errors) { AdicionarErroProcessamento(error.Description); } return(CustomResponse()); }
public async Task <ActionResult> Registrar(UsuarioRegistro usuarioRegistro) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } var user = new IdentityUser { UserName = usuarioRegistro.Email, Email = usuarioRegistro.Email, EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, usuarioRegistro.Senha); if (result.Succeeded) { var funcao = Funcao.ObterEnumIdPeloNome(usuarioRegistro.Funcao); var responsavelResult = await RegistrarResponsavel(usuarioRegistro); if (!responsavelResult.ValidationResult.IsValid) { await _userManager.DeleteAsync(user); return(CustomResponse(responsavelResult.ValidationResult)); } await _userManager.AddClaimAsync(user, new Claim("NivelDeAcesso", funcao.ToString("d2"))); return(CustomResponse(await GerarJwt(usuarioRegistro.Email))); } foreach (var error in result.Errors) { AdicionarErroProcessamento(error.Description); } return(CustomResponse()); }