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); } }
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); } }
public void Salvar(Cliente cliente) { if (cliente.Id > 0) Alterar(cliente); else Inseri(cliente); }
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; }
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); } }
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); } }