public IActionResult Creditos() { setupNav(); Cliente cliente = (Cliente)_userManager.GetUserAsync(this.User).Result; ContaDeCreditos creditos = _context.ContaDeCreditoses .Include(c => c.HistoricoTransacoeMonetarias) .Single(n => n.ContaDeCreditosId == cliente.ContaDeCreditosId); return(View(creditos)); }
public async Task <IActionResult> RegisterCliente(RegisterClienteViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { HistoricoTransacoeMonetarias h1 = new HistoricoTransacoeMonetarias(); ContaDeCreditos conta = new ContaDeCreditos(); conta.HistoricoTransacoeMonetarias = h1; Cliente user = new Cliente { Nome = model.Nome, Apelido = model.Apelido, UserName = model.Email, Email = model.Email, ContaDeCreditos = conta }; var result = await _userManager.CreateAsync(user, model.Password);// cria um user com a pw if (result.Succeeded) { Notificacao notificacao1 = new Notificacao() { Mensagem = "Bem vindo à plataforma", Tipo = Notificacao.TYPE_INFO, Lida = false, UtilizadorId = user.Id }; _context.Notificacao.Add(notificacao1); Notificacao notificacao2 = new Notificacao() { Mensagem = "Confirme o seu email", Tipo = Notificacao.TYPE_WARNING, Lida = false, UtilizadorId = user.Id }; _context.Notificacao.Add(notificacao2); await _userManager.AddToRoleAsync(user, Roles.ROLE_CLIENTE);//atribui a role // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Autenticacao", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await _emailSender.SendEmailAsync(model.Email, "Confirm your account", $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); await _signInManager.SignInAsync(user, isPersistent : false);//para ele depois fazer login, regista-se e fica logo loged-in _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl));// redirecionar para o homeloged in? sim xD } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public AluguerControllerTest() { clienteTest = (Cliente)UserManagerMock.CLIENTE_TEST; contaTest = UserManagerMock.CONTA_CREDITOS_TEST; historicoTest = UserManagerMock.HISTORICO_TEST; }