public async Task <ResponseCommand> Handle(CreateUserCommand command) { var response = new ResponseCommand(); command.Validate(); if (command.Invalid) { response.AddNotifications(command.Notifications); return(response); } if (await _userRepository.UserExiste(command.Login) != null) { response.AddNotification(new Notification("Usuario", "Usuário já existe.")); return(response); } var user = new Models.Usuario(command.Login, command.Senha); await _userRepository.Save(user); response.AddValue(new { Mensagem = "Usuário Cadastrado", Id = user.Id, Login = user.Login }); return(response); }
private static Task HandleExceptionAsync(HttpContext context, Exception ex) { var code = HttpStatusCode.InternalServerError; // 500 if unexpected var response = new ResponseCommand(); response.AddNotification("Error", $"OCorreu um erro inesperado. {ex.Message}."); var result = JsonConvert.SerializeObject(response); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)code; return(context.Response.WriteAsync(result)); }
public async Task <ResponseCommand> Login([FromBody] UserCommandDTO userCommand) { var response = new ResponseCommand(); var userCreate = new Domain.Models.Usuario(userCommand.Login, userCommand.Senha); var user = await _userRepository.GetUser(userCreate.Login, userCreate.Senha); if (user == null) { response.AddNotification(new Notification("Login", "Usuario ou Senha inválidos.")); return(response); } var instaceToken = new TokenService(_configuration); var token = await instaceToken.GenerateToken(user); response.AddValue(new { Mensagem = "Login efetuado com sucesso", Token = token }); return(response); }
public async Task <ResponseCommand> Handle(CreateContaCommand command) { var response = new ResponseCommand(); command.Validate(); if (command.Invalid) { response.AddNotifications(command.Notifications); return(response); } if (await _contaRepository.ContaExiste(command.NumeroConta)) { response.AddNotification(new Notification("Conta", "A conta informada já existe!")); return(response); } var conta = new ContaCorrente(command.NumeroConta); await _contaRepository.CadastrarConta(conta); response.AddValue(command.NumeroConta); return(response); }