public HttpResponseMessage Update(int id, PatrocinioModel model) { try { PatrocinioEntity patrocinio = ModelToEntity(model); patrocinio.Id = id; business.Update(patrocinio); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message.ToString())); } }
public PatrocinioEntity GetById(int id) { try { OpenConnection(); using (var cmd = new SqlCommand("", con)) { cmd.CommandText = "UP_PATROCINIO_BUSCAR"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = Convert.ToInt32(id); dr = cmd.ExecuteReader(); PatrocinioEntity patrocinio = null; if (dr.HasRows) { while (dr.Read()) { patrocinio = new PatrocinioEntity() { Id = Convert.ToInt32(dr["ID"]), Seguradora = new SeguradoraEntity() { Id = Convert.ToInt32(dr["SEGURADORA_ID"]), Nome = Convert.ToString(dr["SEGURADORA_NOME"]), CNPJ = Convert.ToString(dr["SEGURADORA_CNPJ"]) }, Representante = new RepresentanteEntity() { Id = Convert.ToInt32(dr["REPRESENTANTE_ID"]), Nome = Convert.ToString(dr["REPRESENTANTE_NOME"]), CNPJ = Convert.ToString(dr["REPRESENTANTE_CNPJ"]) } }; } } return(patrocinio); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { CloseConnection(); } }
public void Insert(PatrocinioEntity patrocinio) { try { OpenConnection(); using (var cmd = new SqlCommand("", con)) { cmd.CommandText = "UP_PATROCINIO_CADASTRAR"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@SEGURADORA_ID", SqlDbType.Int)).Value = Convert.ToInt32(patrocinio.Seguradora.Id); cmd.Parameters.Add(new SqlParameter("@REPRESENTANTE_ID", SqlDbType.Int)).Value = Convert.ToInt32(patrocinio.Representante.Id); cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { CloseConnection(); } }
public void Update(PatrocinioEntity patrocinio) => repository.Update(patrocinio);
public void Insert(PatrocinioEntity patrocinio) => repository.Insert(patrocinio);