public override bool Eliminar(int id) { bool paso = false; _contexto = new DAL.Contexto(); try { var Ant = _contexto.Renta.Find(id); var cantidad = Ant.Detalle.Count; if (Ant != null) { _contexto.Rentadetalle.RemoveRange(_contexto.Rentadetalle.Where(x => x.RentaId == Ant.RentaId)); _contexto.Entry(Ant).State = System.Data.Entity.EntityState.Deleted; _contexto.Clientes.Find(Ant.ClienteId).VehiculosRentados -= cantidad; if (_contexto.SaveChanges() > 0) { paso = true; } } } catch (Exception) { } finally { _contexto.Dispose(); } return(paso); }
private void Modificarbutton_Click(object sender, EventArgs e) { DAL.Contexto contexto = new DAL.Contexto(); Cotizaciones cotizacion = new Cotizaciones(); cotizacion = contexto.Cotizaciones.Find(1); contexto.Dispose();//me desconecto aqui contexto = new DAL.Contexto(); cotizacion.AgregarDetalle(1, "Croissant", 2); cotizacion.AgregarDetalle(1, "Croissant", 2); cotizacion.AgregarDetalle(1, "Croissant", 2); cotizacion.AgregarDetalle(1, "Croissant", 2); cotizacion.AgregarDetalle(1, "Croissant", 2); //recorrer el detalle foreach (var item in cotizacion.Detalle) { item.CotizacionId = cotizacion.CotizacionId; contexto.Entry(item).State = EntityState.Added; } contexto.SaveChanges(); }
public override bool Modificar(Rentas renta) { bool paso = false; _contexto = new DAL.Contexto(); try { var rentaAnt = _contexto.Renta.Find(renta.RentaId); var detalleAnt = _contexto.Rentadetalle.Where(r => r.RentaId == rentaAnt.RentaId).AsNoTracking().ToList(); var cantidad = rentaAnt.Detalle.Count; _contexto.Entry(rentaAnt).State = EntityState.Deleted; _contexto.Entry(renta).State = EntityState.Modified; _contexto.Clientes.Find(rentaAnt.ClienteId).VehiculosRentados += cantidad; if (_contexto.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } finally { _contexto.Dispose(); } return(paso); }
public override Rentas Buscar(int id) { Rentas renta = new Rentas(); _contexto = new DAL.Contexto(); try { renta = _contexto.Renta.Find(id); if (renta != null) { renta.Detalle.Count(); } } catch (Exception) { throw; } finally { _contexto.Dispose(); } return(renta); }
public override bool Guardar(Rentas renta) { bool paso = false; _contexto = new DAL.Contexto(); try { var cantidad = renta.Detalle.Count; if (_contexto.Renta.Add(renta) != null) { _contexto.Clientes.Find(renta.ClienteId).VehiculosRentados += cantidad; _contexto.SaveChanges(); paso = true; } } catch (Exception) { throw; } finally { _contexto.Dispose(); } return(paso); }
public bool GuardarDetalle(RentasDetalles detalle) { bool paso = false; _contexto = new DAL.Contexto(); try { if (_contexto.Rentadetalle.Add(detalle) != null) { _contexto.SaveChanges(); paso = true; } } catch (Exception) { throw; } finally { _contexto.Dispose(); } return(paso); }
public override List <Rentas> GetList(Expression <Func <Rentas, bool> > expression) { _contexto = new DAL.Contexto(); List <Rentas> lista = new List <Rentas>(); try { lista = _contexto.Renta.Where(expression).ToList(); foreach (var item in lista) { item.Detalle.Count(); } } catch (Exception) { throw; } finally { _contexto.Dispose(); } return(lista); }