public static void Inserir(string nome)
        {
            using (MeuBancoEntities context = new MeuBancoEntities())
            {
                Categoria c = new Categoria();
                c.Nome = nome;

                context.Categorias.Add(c);
                context.SaveChanges();
            }
        }
Exemple #2
0
 public static void Inserir(string marca, string modelo, string motor, string cor, double valor)
 {
     using (MeuBancoEntities context = new MeuBancoEntities())
     {
         Produto produto = new Produto
         {
             Marca  = marca,
             Modelo = modelo,
             Motor  = motor,
             Cor    = cor,
             Valor  = valor
         };
         context.Produtos.Add(produto);
         context.SaveChanges();
     }
 }
 public static bool Remover(int id)
 {
     using (MeuBancoEntities context = new MeuBancoEntities())
     {
         var categoria_ = from Categoria c in context.Categorias
                          where c.Id == id
                          select c;
         if (categoria_.Count() > 0)
         {
             context.Categorias.Remove(categoria_.First());
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
 public static void Atualizar(int id, string nome)
 {
     using (MeuBancoEntities context = new MeuBancoEntities())
     {
         var categoria_ = from Categoria c in context.Categorias
                          where c.Id == id
                          select c;
         if (categoria_.Count() > 0)
         {
             Categoria c = categoria_.First();
             c.Nome = nome;
             context.SaveChanges();
         }
         else
         {
             throw new Exception("");
         }
     }
 }
Exemple #5
0
 public static void Atualizar(int id, string marca, string modelo, string motor, string cor, double valor)
 {
     using (MeuBancoEntities context = new MeuBancoEntities())
     {
         var produto_ = from Produto p in context.Produtos
                        where p.Id == id
                        select p;
         if (produto_.Count() > 0)
         {
             Produto p = produto_.First();
             p.Marca  = marca;
             p.Modelo = modelo;
             p.Motor  = motor;
             p.Cor    = cor;
             p.Valor  = valor;
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Não existe esse produto no estoque.");
         }
     }
 }