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 void Remover(int id) { using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var produto_ = from Produto p in context.ProdutoSet where p.Racao.Id == id select p; if (produto_.Count() > 0) { throw new NegocioException(NegocioExcCode.RACAOCOMPRODUTO, id.ToString()); } var racao_ = from Racao r in context.RacaoSet where r.Id == id select r; if (racao_.Count() > 0) { context.RacaoSet.Remove(racao_.First()); 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 void Atualizar(int id, double preço) { if (preço < 0) { throw new NegocioException(NegocioExcCode.PRODUTOPRECOVAZIO, ""); } using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var produto_ = from Produto p in context.ProdutoSet where p.Id == id select p; if (produto_.Count() > 0) { Produto p = produto_.First(); p.Preço = preço; context.SaveChanges(); } else { throw new NegocioException(NegocioExcCode.PRODUTOIDINEXISTENTE, id.ToString()); } } }
public static int Inserir(double preço, int idRacao) { if (preço < 0) { throw new NegocioException(NegocioExcCode.PRODUTOPRECOVAZIO, ""); } int idNovo = -1; using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var racao_ = from Racao r in context.RacaoSet where r.Id == idRacao select r; if (racao_.Count() > 0) { Produto p = new Produto(); p.Preço = preço; p.Racao = racao_.First(); context.ProdutoSet.Add(p); context.SaveChanges(); idNovo = p.Id; } else { throw new NegocioException(NegocioExcCode.RACAOIDINEXISTENTE, idRacao.ToString()); } } return(idNovo); }
public static void Atualizar(int id, int quantidade) { if (quantidade < 0) { throw new NegocioException(NegocioExcCode.CARRINHOQUANTIDADEVAZIO, ""); } if (quantidade > 9) { throw new NegocioException(NegocioExcCode.CARRINHOQUANTIDADEMAIORQUENOVE, ""); } using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var carrinho_ = from Carrinho c in context.CarrinhoSet where c.Id == id select c; if (carrinho_.Count() > 0) { Carrinho c = carrinho_.First(); c.Quantidade = quantidade; context.SaveChanges(); } else { throw new NegocioException(NegocioExcCode.CARRINHOIDINEXISTENTE, id.ToString()); } } }
public static int Inserir(int quantidade, int idProduto) { if (quantidade < 0) { throw new NegocioException(NegocioExcCode.CARRINHOQUANTIDADEVAZIO, ""); } if (quantidade > 9) { throw new NegocioException(NegocioExcCode.CARRINHOQUANTIDADEMAIORQUENOVE, ""); } int idNovo = -1; using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var produto_ = from Produto p in context.ProdutoSet where p.Id == idProduto select p; if (produto_.Count() > 0) { Carrinho c = new Carrinho(); c.Quantidade = quantidade; c.Produtos = produto_.First(); context.CarrinhoSet.Add(c); context.SaveChanges(); idNovo = c.Id; } else { throw new NegocioException(NegocioExcCode.PRODUTOIDINEXISTENTE, idProduto.ToString()); } } return(idNovo); }