コード例 #1
0
ファイル: ClienteAplicacao.cs プロジェクト: itasouza/WebApi
        public void Inseri(Cliente cliente)
        {
            var strQuery = "";
            strQuery += "INSERT INTO CLIENTES (NOME, DATA_NASCIMENTO,EMAIL, SENHA)";
            strQuery += string.Format(" VALUES ('{0}','{1}','{2}','{3}' )", cliente.Nome, cliente.DataNascimento, cliente.Email, cliente.senha);

            using (contexto = new Contexto())
            {
                contexto.ExecutaComando(strQuery);
            }
        }
コード例 #2
0
ファイル: DefaultController.cs プロジェクト: itasouza/WebApi
 public HttpResponseMessage CadastroCadastro(Cliente cliente)
 {
     try
     {
         return Request.CreateResponse(HttpStatusCode.OK, "cadastro do cliente " + cliente.Nome + " realizado");
     }
     catch (Exception ex)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
     }
 }
コード例 #3
0
ファイル: ClienteAplicacao.cs プロジェクト: itasouza/WebApi
 public void Salvar(Cliente cliente)
 {
     if (cliente.Id > 0)
         Alterar(cliente);
     else
         Inseri(cliente);
 }
コード例 #4
0
ファイル: ClienteAplicacao.cs プロジェクト: itasouza/WebApi
        private List<Cliente> TransformaReaderEmListaObjetos(SqlDataReader reader)
        {
            var clientes = new List<Cliente>();
            while (reader.Read())
            {

                Cliente cliente = new Cliente()
                {
                    Id = reader["id"] == DBNull.Value ? 0 : Convert.ToInt32(reader["id"]),
                    Nome = reader["nome"] == DBNull.Value ? string.Empty : reader["nome"].ToString(),
                    DataNascimento = reader["data_nascimento"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(reader["data_nascimento"]),
                    Email = reader["email"] == DBNull.Value ? string.Empty : reader["email"].ToString()

                };

                clientes.Add(cliente);
            }
            reader.Close();
            return clientes;
        }
コード例 #5
0
ファイル: ClienteAplicacao.cs プロジェクト: itasouza/WebApi
        private void Alterar(Cliente cliente)
        {
            var strQuery = "";
            strQuery += "UPDATE CLIENTES SET";
            strQuery += string.Format(" NOME = '{0}', ", cliente.Nome);
            strQuery += string.Format(" DATA_NASCIMENTO = '{0}', ", cliente.DataNascimento);
            strQuery += string.Format(" EMAIL = '{0}' ", cliente.Email);
            strQuery += string.Format(" SEMHA = '{0}' ", cliente.senha);
            strQuery += string.Format(" WHERE IDALUNO= '{0}' ", cliente.Id);

            using (contexto = new Contexto())
            {
                contexto.ExecutaComando(strQuery);
            }
        }
コード例 #6
0
ファイル: DefaultController.cs プロジェクト: itasouza/WebApi
        public HttpResponseMessage PostCadastro(Cliente cliente)
        {
            try
            {
                var tCliente = new ClienteAplicacao();
                tCliente.Inseri(cliente);
                return Request.CreateResponse(HttpStatusCode.OK, "Cadastro do cliente" + cliente.Nome + "realizado.");
            }
            catch (Exception ex )
            {

                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }
        }