protected void btnSeguir_Click(object sender, EventArgs e) { Venta venta = new Venta(); VentaNegocio negocio = new VentaNegocio(); List <Venta> listaVenta = new List <Venta>(); Venta aux = new Venta(); int contador = 0; cliente = (Usuario)Session[Session.SessionID + "Usuario"]; if (Session[Session.SessionID + "Usuario"] == null) { Response.Redirect("Login.aspx"); } if (cliente.direccion.Calle == "Sin datos") { Response.Redirect("AgregarDireccion.aspx"); } else { venta.cliente = (Usuario)Session[Session.SessionID + "Usuario"]; venta.carro = (Carro)Session[Session.SessionID + "elemento"]; venta.fecha = DateTime.Now.Date; foreach (var item in venta.carro.Item) { Articulo producto = new Articulo(); ArticuloNegocio negocioArticulo = new ArticuloNegocio(); producto = negocioArticulo.ListarArticulos().Find(k => k.Id == item.Id); if (item.CantidadUnidades <= producto.Stock) { producto.Stock = producto.Stock - item.CantidadUnidades; negocioArticulo.ModificarStockProducto(producto); venta.producto = item; if (contador == 0) { negocio.AgregarVenta(venta); listaVenta = negocio.ListarVentas(); contador++; } aux = listaVenta[listaVenta.Count - 1]; venta.Id = aux.Id; negocio.AgregarProductos_Por_Ventas(venta); } else { Response.Redirect("Default.aspx"); break; } } Response.Redirect("ClienteCompra.aspx"); } }