public HttpResponseMessage Update(int id, RepresentanteModel model) { try { RepresentanteEntity entity = ModelToEntity(model); entity.Id = id; business.Update(entity); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString())); } }
public void Update(RepresentanteEntity representante) { try { if (string.IsNullOrEmpty(representante.Nome) && string.IsNullOrEmpty(representante.CNPJ)) { throw new ArgumentNullException("Nome ou CNPJ devem ser preenchidos"); } repository.Update(representante); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }
public RepresentanteEntity GetById(int id) { try { OpenConnection(); using (var cmd = new SqlCommand("", con)) { cmd.CommandText = "UP_REPRESENTANTE_BUSCAR"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = Convert.ToInt32(id); dr = cmd.ExecuteReader(); RepresentanteEntity representante = null; if (dr.HasRows) { while (dr.Read()) { representante = new RepresentanteEntity() { Id = Convert.ToInt32(dr["ID"]), Nome = Convert.ToString(dr["NOME"]), CNPJ = Convert.ToString(dr["CNPJ"]), Ativo = Convert.ToBoolean(dr["BIT_ATIVO"]), DataCriacao = Convert.ToDateTime(dr["DATA_CRIACAO"]) }; } } return(representante); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { CloseConnection(); } }
public void Insert(RepresentanteEntity representante) { try { OpenConnection(); using (var cmd = new SqlCommand("", con)) { cmd.CommandText = "UP_REPRESENTANTE_CADASTRAR"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@NOME", SqlDbType.VarChar)).Value = Convert.ToString(representante.Nome).Trim(); cmd.Parameters.Add(new SqlParameter("@CNPJ", SqlDbType.VarChar)).Value = Convert.ToString(representante.CNPJ).Trim(); cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { CloseConnection(); } }