public static void Atualizar(int id, int peso, string nome) { if (peso < 1) { throw new NegocioException(NegocioExcCode.RACAOPESOMENORQUEUM, ""); } using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var racao_ = from Racao r in context.RacaoSet where r.Id == id select r; if (racao_.Count() > 0) { Racao r = racao_.First(); r.Peso = peso; r.Nome = nome; context.SaveChanges(); } else { throw new NegocioException(NegocioExcCode.RACAOIDINEXISTENTE, id.ToString()); } } }
public static int Inserir(int peso, string nome) { if (peso < 1) { throw new NegocioException(NegocioExcCode.RACAOPESOMENORQUEUM, ""); } if (nome.Length == 0) { throw new NegocioException(NegocioExcCode.RACAOSEMNOME, ""); } int idNovo = -1; using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { Racao r = new Racao(); r.Peso = peso; r.Nome = nome; context.RacaoSet.Add(r); context.SaveChanges(); idNovo = r.Id; } return(idNovo); }
public static Racao Consultar(int id) { Racao racao = null; using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var racao_ = from Racao r in context.RacaoSet where r.Id == id select r; if (racao_.Count() > 0) { racao = racao_.First(); } else { throw new NegocioException(NegocioExcCode.RACAOIDINEXISTENTE, id.ToString()); } } return(racao); }