public List <Detalle_FacturaBL> obtenerDetalles(int numeroFactura) { this.Consecutivo_Factura = numeroFactura; Detalles_FacturaTO detalleTO = new Detalles_FacturaTO(); detalleTO.Consecutivo_Factura = this.Consecutivo_Factura; List <Detalles_FacturaTO> lista = new List <Detalles_FacturaTO>(); List <Detalle_FacturaBL> listaBL = new List <Detalle_FacturaBL>(); lista = detalleDAO.obtenerDetalles(detalleTO); if (lista != null) { Detalle_FacturaBL dBL; for (int i = 0; i < lista.Count; i++) { dBL = new Detalle_FacturaBL(); dBL.Cantidad = lista[i].Cantidad; dBL.Codigo_Producto = lista[i].Codigo_Producto; dBL.Consecutivo_Factura = lista[i].Consecutivo_Factura; listaBL.Add(dBL); } } return(listaBL); }
public List <Detalles_FacturaTO> obtenerDetalles(Detalles_FacturaTO detallesTO) { List <Detalles_FacturaTO> lista = new List <Detalles_FacturaTO>(); using (context = new EmpresaEntities()) { var query = from detalle in context.Detalle_Factura where detallesTO.Consecutivo_Factura == detalle.Factura select detalle; Detalles_FacturaTO dTO; if (query != null) { foreach (Detalle_Factura df in query) { dTO = new Detalles_FacturaTO(); dTO.Consecutivo_Factura = df.Factura; dTO.Cantidad = df.Cantidad; dTO.Codigo_Producto = df.Producto; lista.Add(dTO); } } else { throw new Exception("No hay productos para mostrar de la factura"); } } return(lista); }
public void agregarDetalle(String factura, String producto, String cantidad) { try { this.Consecutivo_Factura = int.Parse(factura); this.Codigo_Producto = int.Parse(producto); this.Cantidad = int.Parse(cantidad); Detalles_FacturaTO detalleTO = new Detalles_FacturaTO(); detalleTO.Consecutivo_Factura = this.Consecutivo_Factura; detalleTO.Codigo_Producto = this.Codigo_Producto; detalleTO.Cantidad = this.Cantidad; detalleDAO = new Detalles_FacturaDAO(); detalleDAO.insertarDetalle(detalleTO); } catch (Exception) { throw; } }
public void insertarDetalle(Detalles_FacturaTO detalleTO) { try { ProductoDAO productoDAO = new ProductoDAO(); using (context = new EmpresaEntities()) { Detalle_Factura detalleDAO = new Detalle_Factura { Factura = detalleTO.Consecutivo_Factura, Producto = detalleTO.Codigo_Producto, Cantidad = detalleTO.Cantidad }; ProductoTO productoTO = new ProductoTO(); productoTO.Codigo = detalleTO.Codigo_Producto; productoDAO.extraerProducto(productoTO); if (detalleTO.Cantidad == 0) { throw new Exception("La cantidad de un producto no puede ser 0"); } if (productoTO.CantidadInventario < detalleTO.Cantidad) { throw new Exception("Error, no hay suficientes productos para satisfcaer la demanda"); } context.Detalle_Factura.Add(detalleDAO); context.SaveChanges(); productoDAO.extraerProductoCantidad(detalleTO.Codigo_Producto, detalleTO.Cantidad); } } catch (Exception) { throw; } }