Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }