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(Deposito entity) { var BaseDatos = base.Buscar(entity.DepositoId); bool paso = false; _contexto = new DAL.Contexto(); try { _contexto.Cuenta.Find(entity.CuentaId).Balance -= BaseDatos.Monto; _contexto.Cuenta.Find(entity.CuentaId).Balance += entity.Monto; _contexto.Entry(entity).State = System.Data.Entity.EntityState.Modified; if (_contexto.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } return(paso); }
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 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); }
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 override bool Guardar(Prestamos entity) { bool paso = false; decimal monto = 0; _contexto = new DAL.Contexto(); try { foreach (var item in entity.Cuotas) { monto += item.MontoPorCuota; } _contexto.Cuenta.Find(entity.CuentaId).Balance += monto; _contexto.Prestamos.Add(entity); if (_contexto.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } return(paso); }
public override bool Guardar(Prestamo entity) { bool paso = false; decimal monto = 0; _contexto = new DAL.Contexto(); try { foreach (var item in entity.Detalle) { monto += item.Capital + item.Interes; } _contexto.Cuenta.Find(entity.IdCuenta).Balance += monto; _contexto.Prestamos.Add(entity); if (_contexto.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } return(paso); }
public override bool Modificar(Prestamo entity) { _contexto = new DAL.Contexto(); decimal montoBaseDatos = 0; decimal montoEntidad = 0; bool paso = false; try { //Busca el detalle anterior en base de datos var detalleAnterior = _contexto.Cuotas.Where(x => x.IdPrestamo == entity.IdPrestamo).AsNoTracking().ToList(); //Agrega a la variable montoBaseDatos el monto del capital mas el interes foreach (var item in detalleAnterior) { montoBaseDatos += item.Capital + item.Interes; } //Agrega a la variable montoEntidad el monto del capital mas el interes foreach (var item in entity.Detalle) { montoEntidad += item.Capital + item.Interes; } _contexto.Cuenta.Find(entity.IdCuenta).Balance -= montoBaseDatos; _contexto.Cuenta.Find(entity.IdCuenta).Balance += montoEntidad; //Marca como borrado alguna cuota que este en base de datos y no en la lista detalle if (entity.Detalle.Count < detalleAnterior.Count) { foreach (var item in detalleAnterior) { if (!entity.Detalle.Exists(x => x.IdCuota.Equals(item.IdCuota))) { _contexto.Entry(item).State = System.Data.Entity.EntityState.Deleted; } } } //Modifica o agrega una nueva cuota foreach (var item in entity.Detalle) { _contexto.Entry(item).State = item.IdCuota == 0 ? EntityState.Added : EntityState.Modified; } //modifica la entidad _contexto.Entry(entity).State = EntityState.Modified; //Guarda paso = _contexto.SaveChanges() > 0 ? true : false; } catch (Exception) { throw; } return(paso); }
private void Nuevobutton_Click(object sender, EventArgs e) { DAL.Contexto contexto = new DAL.Contexto(); Cotizaciones cotizacion = new Cotizaciones() { CotizacionId = 0, Fecha = new DateTime(2018, 1, 1), Monto = 100 }; cotizacion.AgregarDetalle(1, "Pan", 2); cotizacion.AgregarDetalle(1, "Mantequilla", 1); contexto.Cotizaciones.Add(cotizacion); contexto.SaveChanges(); }
public override bool Guardar(Deposito entity) { bool paso = false; _contexto = new DAL.Contexto(); try { _contexto.Cuenta.Find(entity.CuentaId).Balance += entity.Monto; _contexto.Depositos.Add(entity); if (_contexto.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } return(paso); }
public override bool Eliminar(int id) { bool paso = false; _contexto = new DAL.Contexto(); try { var Deposito = _contexto.Depositos.Find(id); _contexto.Cuenta.Find(Deposito.CuentaId).Balance -= Deposito.Monto; _contexto.Entry(Deposito).State = System.Data.Entity.EntityState.Deleted; if (_contexto.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } 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); }