public async Task <IActionResult> Register(RegisterViewModel model) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(Response <RegisterViewModel>(model)); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email, EmailConfirmed = true }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "CanWriteAlunoData"); var aluno = new AlunoViewModel() { Id = Guid.NewGuid(), IdUsuario = user.Id, Matricula = model.Matricula, Nome = model.Nome }; _alunoAppService.Register(aluno); return(Response <AlunoViewModel>(aluno)); } AddIdentityErrors(result); return(Response <AlunoViewModel>(new AlunoViewModel() { Matricula = model.Matricula, Nome = model.Nome })); }