public static bool Buscar(Expression <Func <ProductoFactura, bool> > criterio, bool relaciones) { using (var db = new Repositorio <ProductoFactura>()) { if ((productoFacturaReturned = db.Buscar(criterio)) != null) { FacturasBLL.Buscar(x => x.FacturaId == productoFacturaReturned.FacturaId, true); productoFacturaReturned.Factura = FacturasBLL.facturaReturned; ProductosBLL.Buscar(x => x.ProductoId == productoFacturaReturned.ProductoId, true); productoFacturaReturned.Producto = ProductosFacturasBLL.productoFacturaReturned.Producto; return(true); } return(false); } }
public static bool Buscar(Expression <Func <Pago, bool> > criterio, bool relaciones) { using (var db = new Repositorio <Pago>()) { if ((pagoReturned = db.Buscar(criterio)) != null) { if (relaciones) { FacturasBLL.Buscar(x => x.FacturaId == pagoReturned.FacturaId, true); pagoReturned.Factura = FacturasBLL.facturaReturned; } return(true); } return(false); } }
public static bool GetList(Expression <Func <ProductoFactura, bool> > criterio, bool relaciones) { using (var db = new Repositorio <ProductoFactura>()) { if ((productoFacturaReturnedList = db.GetList(criterio)) != null) { if (relaciones) { foreach (var productoFactura in productoFacturaReturnedList) { FacturasBLL.Buscar(x => x.FacturaId == productoFactura.FacturaId, true); productoFactura.Factura = FacturasBLL.facturaReturned; ProductosBLL.Buscar(x => x.ProductoId == productoFactura.ProductoId, true); productoFactura.Producto = ProductosBLL.productoReturned; } } return(true); } return(false); } }
public static bool Modificar(Facturas Factura) { bool paso = false; Contexto contexto = new Contexto(); try { var factura = FacturasBLL.Buscar(Factura.FacturaId); if (factura != null) { foreach (var item in factura.Detalles) { contexto.Ropas.Find(item.RopaId).Inventario += item.Cantidad; if (!Factura.Detalles.ToList().Exists(v => v.Id == item.Id)) { item.Ropas = null; contexto.Entry(item).State = EntityState.Deleted; } } foreach (var item in Factura.Detalles) { contexto.Ropas.Find(item.RopaId).Inventario -= item.Cantidad; var estado = item.Id > 0 ? EntityState.Modified : EntityState.Added; contexto.Entry(item).State = estado; } Facturas Anterior = FacturasBLL.Buscar(Factura.FacturaId); //identificar la diferencia ya sea restada o sumada decimal diferencia; diferencia = Factura.Devuelta - Anterior.Devuelta; //aplicar diferencia al inventario Facturas facturas = FacturasBLL.Buscar(Factura.FacturaId); facturas.Devuelta += diferencia; FacturasBLL.Modificar(facturas); contexto.Entry(Factura).State = EntityState.Modified; } if (contexto.SaveChanges() > 0) { paso = true; } contexto.Dispose(); } catch (Exception) { throw; } return(paso); }