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 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 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 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 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(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 List <Racao> Listar() { List <Racao> racoes = new List <Racao>(); using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { racoes.AddRange(context.RacaoSet); } return(racoes); }
public static List <Produto> Listar() { List <Produto> produtos = new List <Produto>(); using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { produtos.AddRange(context.ProdutoSet); } return(produtos); }
public static List <Carrinho> Listar() { List <Carrinho> carrinhos = new List <Carrinho>(); using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { carrinhos.AddRange(context.CarrinhoSet); } return(carrinhos); }
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); }
public static Carrinho Consultar(int id) { Carrinho carrinho = null; using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var carrinho_ = from Carrinho c in context.CarrinhoSet.Include("Produtos") where c.Id == id select c; if (carrinho_.Count() > 0) { carrinho = carrinho_.First(); } else { throw new NegocioException(NegocioExcCode.CARRINHOIDINEXISTENTE, id.ToString()); } } return(carrinho); }
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); }
public static Produto Consultar(int id) { Produto produto = null; using (EntitiesDogGentleman context = new EntitiesDogGentleman()) { var produto_ = from Produto p in context.ProdutoSet.Include("Racao") where p.Id == id select p; if (produto_.Count() > 0) { produto = produto_.First(); } else { throw new NegocioException(NegocioExcCode.PRODUTOIDINEXISTENTE, id.ToString()); } } return(produto); }