public async Task <IHttpActionResult> PutTipoCor(int id, TipoCor tipoCor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tipoCor.Id) { return(BadRequest()); } db.Entry(tipoCor).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TipoCorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public Retorno Salvar(TipoCor Entity) { try { Retorno retorno = PreenchimentoObrigatorio(Entity); if (retorno.IsValido) { retorno = VerificarExistencia(Entity); if (retorno.IsValido) { if (Entity.Codigo == 0) { retorno = new DataTipoCor().Incluir(Entity); } else { retorno = new DataTipoCor().Alterar(Entity); } } } return(retorno); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
public Retorno VerificarExistencia(TipoCor Entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("SELECT 1 FROM TB_TIPO_COR "); CommandSQL.AppendLine("WHERE TB_TIPO_COR.DESCRICAO = @DESCRICAO "); CommandSQL.AppendLine("AND TB_TIPO_COR.CODIGO <> @CODIGO "); Command = CriaComandoSQL(CommandSQL.ToString()); Abrir(); Command.Parameters.AddWithValue("@DESCRICAO", Entity.Descricao); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Reader = Command.ExecuteReader(); while (Reader.Read()) { return(new Retorno(false, String.Format(Mensagens.MSG_04, "TipoCor", "Descricao"))); } return(new Retorno(true)); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno Consultar(TipoCor Entity) { try { TipoCor TipoCor = new TipoCor(); CommandSQL = new StringBuilder(); CommandSQL.AppendLine("SELECT "); CommandSQL.AppendLine("TB_TIPO_COR.CODIGO, "); CommandSQL.AppendLine("TB_TIPO_COR.DESCRICAO "); CommandSQL.AppendLine("FROM TB_TIPO_COR "); CommandSQL.AppendLine("WHERE TB_TIPO_COR.CODIGO = @CODIGO "); Command = CriaComandoSQL(CommandSQL.ToString()); Abrir(); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Reader = Command.ExecuteReader(); while (Reader.Read()) { TipoCor = FillEntity(Reader); } return(new Retorno(TipoCor)); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno Pesquisar(TipoCor Entity, int Pagina, int QntPagina) { try { List <TipoCor> TipoCors = new List <TipoCor>(); int Limite = (Pagina - 1) * QntPagina; CommandSQL = new StringBuilder(); CommandSQL.AppendLine("SELECT "); CommandSQL.AppendLine("TB_TIPO_COR.CODIGO, "); CommandSQL.AppendLine("TB_TIPO_COR.DESCRICAO "); CommandSQL.AppendLine("FROM TB_TIPO_COR "); CommandSQL.AppendLine("WHERE (TB_TIPO_COR.DESCRICAO LIKE '%" + Entity.Descricao + "%' )"); CommandSQL.AppendLine("LIMIT @QNT_PAGINA OFFSET @LIMITE"); Command = CriaComandoSQL(CommandSQL.ToString()); Abrir(); Command.Parameters.AddWithValue("@QNT_PAGINA", QntPagina); Command.Parameters.AddWithValue("@LIMITE", Limite); Reader = Command.ExecuteReader(); while (Reader.Read()) { TipoCors.Add(FillEntity(Reader)); } return(new Retorno(TipoCors)); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno PreenchimentoObrigatorio(TipoCor Entity) { if (String.IsNullOrEmpty(Entity.Descricao)) { return(new Retorno(false, String.Format(Mensagens.MSG_01, "Descricao"))); } return(new Retorno(true)); }
public async Task <IHttpActionResult> GetTipoCor(int id) { TipoCor tipoCor = await db.tipoCores.FindAsync(id); if (tipoCor == null) { return(NotFound()); } return(Ok(tipoCor)); }
public Retorno Consultar(TipoCor Entity) { try { return(new DataTipoCor().Consultar(Entity)); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
public Retorno Pesquisar(TipoCor Entity, int Pagina, int QntPagina) { try { return(new DataTipoCor().Pesquisar(Entity, Pagina, QntPagina)); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
private Retorno VerificarExistencia(TipoCor Entity) { try { return(new DataTipoCor().VerificarExistencia(Entity)); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
public async Task <IHttpActionResult> PostTipoCor(TipoCor tipoCor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tipoCores.Add(tipoCor); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = tipoCor.Id }, tipoCor)); }
private TipoCor FillEntity(IDataReader reader) { TipoCor TipoCor = new TipoCor(); try { TipoCor.Codigo = ConverterValorReader(reader, "CODIGO", 0); TipoCor.Descricao = ConverterValorReader(reader, "DESCRICAO", String.Empty).ToUpper(); } catch (Exception ex) { throw ex; } return(TipoCor); }
public async Task <IHttpActionResult> DeleteTipoCor(int id) { TipoCor tipoCor = await db.tipoCores.FindAsync(id); if (tipoCor == null) { return(NotFound()); } db.tipoCores.Remove(tipoCor); await db.SaveChangesAsync(); return(Ok(tipoCor)); }
public Retorno Alterar(TipoCor Entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("UPDATE TB_TIPO_COR SET "); CommandSQL.AppendLine("DESCRICAO = @DESCRICAO "); CommandSQL.AppendLine("WHERE CODIGO = @CODIGO"); Command = CriaComandoSQL(CommandSQL.ToString()); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Command.Parameters.AddWithValue("@DESCRICAO", Entity.Descricao.ToUpper()); Abrir(); Command.ExecuteNonQuery(); return(new Retorno(true, String.Format(Mensagens.MSG_02, "Alterado "))); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno Incluir(TipoCor Entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("INSERT INTO TB_TIPO_COR( "); CommandSQL.AppendLine("DESCRICAO) "); CommandSQL.AppendLine("VALUES ("); CommandSQL.AppendLine("@DESCRICAO) "); Command = CriaComandoSQL(CommandSQL.ToString()); Command.Parameters.AddWithValue("@DESCRICAO", Entity.Descricao.ToUpper()); Abrir(); Command.ExecuteNonQuery(); return(new Retorno(true, String.Format(Mensagens.MSG_02, "Salvo"))); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno Excluir(TipoCor Entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("DELETE FROM TB_TIPO_COR WHERE CODIGO = @CODIGO"); Command = CriaComandoSQL(CommandSQL.ToString()); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Abrir(); Command.ExecuteNonQuery(); return(new Retorno(true, String.Format(Mensagens.MSG_02, "Excluido "))); } catch (Exception ex) { if (((MySqlException)ex).Number == 1451) { return(new Retorno(false, Mensagens.MSG_16)); } throw ex; } finally { Fechar(); } }