示例#1
0
        protected void lvProductos_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "addProducto")
            {
                var productoId = Int32.Parse(e.CommandArgument.ToString());

                var producto = ProductoService.GetProductoById(productoId);

                var venta = GetVenta();

                var existe = venta.detalleVenta
                             .SingleOrDefault(i => i.ProductoId.Equals(productoId));

                if (existe == null)
                {
                    var itemPedido = new DetalleVenta()
                    {
                        VentaId    = venta.Id,
                        Cantidad   = 1,
                        producto   = producto,
                        ProductoId = productoId,
                        Precio     = producto.PrecioUnitarioDeVenta
                    };
                    venta.detalleVenta.Add(itemPedido);
                }
                else
                {
                    existe.Cantidad += 1;
                }

                BindVenta(venta);

                Cache.Insert("venta", venta);
            }
        }
        protected void lvProformas_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "agregar")
            {
                var productoId = Convert.ToInt32(e.CommandArgument.ToString());

                var producto = ProductoService.GetProductoById(productoId);

                var proforma = Cache.Get("proforma") as Proforma;

                var existe = proforma.detalleproforma.SingleOrDefault(d => d.ProductoId.Equals(productoId));

                if (existe == null)
                {
                    var detalleproforma = new DetalleProforma()
                    {
                        ProductoId = productoId,
                        producto   = producto,
                        Cantidad   = 1,
                        ProformaId = proforma.Id,
                        Precio     = producto.PrecioUnitarioDeVenta
                    };

                    proforma.detalleproforma.Add(detalleproforma);
                }
                else
                {
                    existe.Cantidad += 1;
                }

                BindProforma(proforma);
                Cache.Insert("proforma", proforma);
            }
        }