public static int Inserir(string nome, double preco, int idCategoria) { int idNovo = -1; if (nome == null || nome.Length == 0) { throw new NegociosExceptions(NegocioExcCode.PRODUTONOMEVAZIO, ""); } { using (BDMrBarberEntities context = new BDMrBarberEntities()) { var categoria_ = from Categoria c in context.Categorias where c.Id == idCategoria select c; if (categoria_.Count() > 0) { Produtos p = new Produtos(); p.Nome = nome; p.Preco = preco; p.Categoria = categoria_.First(); context.Produtos.Add(p); } else { throw new NegociosExceptions(NegocioExcCode.CATEGORIAIDINEXISTENTE, idCategoria.ToString()); } } } return(idNovo); }
public static List <Categoria> Listar() { List <Categoria> categorias = new List <Categoria>(); using (BDMrBarberEntities context = new BDMrBarberEntities()) { // categorias.AddRange(context.Categorias); var test = context.Categorias.ToList(); } return(categorias); }
public static Categoria Consultar(int id) { Categoria categoria = null; using (BDMrBarberEntities context = new BDMrBarberEntities()) { var categoria_ = from Categoria c in context.Categorias where c.Id == id select c; if (categoria_.Count() > 0) { categoria = categoria_.First(); } else { throw new NegociosExceptions(NegocioExcCode.CATEGORIAIDINEXISTENTE, id.ToString()); } } return(categoria); }