Exemplo n.º 1
0
 public bool Delete(T entity)
 {
     using (ModelContainer1 context = new ModelContainer1())
     {
         context.Entry(entity).State = EntityState.Deleted;
         return(context.SaveChanges() > 0);
     }
 }
Exemplo n.º 2
0
 public bool CreatePedidoWithProducts(Pedido pedido)
 {
     using (ModelContainer1 container1 = new ModelContainer1())
     {
         container1.PedidoSet.Add(pedido);
         pedido.Producto.ToList().ForEach(u => container1.Entry(u).State = EntityState.Unchanged);
         return(container1.SaveChanges() > 0);
     }
 }
Exemplo n.º 3
0
 public bool CreateCliente(Cliente cliente)
 {
     using (ModelContainer1 context = new ModelContainer1())
     {
         context.ClienteSet.Add(cliente);
         cliente.Rol.ToList().ForEach(u => context.Entry(u).State = EntityState.Unchanged);
         return(context.SaveChanges() > 0);
     }
 }
Exemplo n.º 4
0
 public void Delete(Expression <Func <T, bool> > predicate)
 {
     using (ModelContainer1 context = new ModelContainer1())
     {
         var entities = context.Set <T>().Where(predicate).ToList();
         entities.ForEach(x => context.Entry(x).State = EntityState.Deleted);
         context.SaveChanges();
     }
 }