Esempio n. 1
0
        public async Task <ActionResult <dynamic> > Post([FromBody] CadastroClienteRequest request)
        {
            UserEntity entity = new UserEntity();

            entity.Username = "******";
            entity.Password = "******";

            var user = UserRepository.Get(entity.Username, entity.Password);


            if (user == null)
            {
                return(NotFound(new { message = "Usuário ou senha inválidos" }));
            }

            var token = new TokenService();

            token.GenerateToken(entity);
            var entityCliente = new Cliente
            {
                Nome           = request.Nome,
                Cpf            = request.Cpf,
                Telefone       = request.Telefone,
                Celular        = request.Celular,
                Email          = request.Email,
                Endereco       = request.Endereco,
                FormaPagamento = request.FormaPagamento
            };

            clienteRepository.Create(entityCliente);
            user.Password = "";

            var response = new CadastroClienteResponse
            {
                SatusCode = StatusCodes.Status200OK,
                Message   = "Cliente Cadastrado Com Sucesso.",
                Data      = entityCliente
            };

            return(new
            {
                user = user,
                message = response
            });
        }
        public IActionResult Post(CadastroClienteRequest request)
        {
            var entity = new Cliente
            {
                Nome        = request.Nome,
                Email       = request.Email,
                Cpf         = request.Cpf,
                DataCriacao = DateTime.Now
            };

            clienteRepository.Create(entity);

            var response = new CadastroClienteResponse
            {
                StatusCode = StatusCodes.Status200OK,
                Message    = "Cliente cadastrado com sucesso.",
                Data       = entity
            };

            return(Ok(response));
        }