public async Task <ResponseCommand> Handle(CreateLancamentoCommand command)
        {
            var response = new ResponseCommand();

            command.Validate();
            if (command.Invalid)
            {
                response.AddNotifications(command.Notifications);
                return(response);
            }

            var lancamento = new Models.Lancamento(
                command.NumeroContaOrigem,
                command.NumeroContaDestino,
                command.Valor);

            await _lancamentoRepository.GerarLancamento(lancamento);

            response.AddValue(new { Mensagem   = "Lançamento efetuado com sucesso.",
                                    Compovante = lancamento.Id,
                                    Origem     = lancamento.NumeroContaOrigem,
                                    Destino    = lancamento.NumeroContaDestino,
                                    Valor      = lancamento.Valor,
                                    Data       = lancamento.DataLancamento.ToString("dd-MM-yyyy") });

            return(response);
        }
        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);
        }
        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);
        }
Example #4
0
        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);
        }