예제 #1
0
        public static bool Modificar(Factura bill)
        {
            bool     paso  = false;
            bool     paso1 = false;
            Contexto db    = new Contexto();

            try
            {
                //Eliminar Detalle de la base de datos si no existe en la lista de el llenaClase
                var Eliminar = FacturaDetalleBLL.GetList(x => x.FacturaId == bill.FacturaId);
                if (bill.BillDetalle.Count < Eliminar.Count)
                {
                    foreach (var itemsEliminar in Eliminar)
                    {
                        if (!bill.BillDetalle.Exists(x => x.Id.Equals(itemsEliminar.Id)))
                        {
                            HerramientasBLL.ArreglarProductoDetalle(itemsEliminar);
                            FacturaDetalleBLL.Eliminar(itemsEliminar.Id);
                        }
                    }
                }

                var billes = Buscar(bill.FacturaId);
                db.Entry(bill).State = EntityState.Modified;
                BLL.HerramientasBLL.ArreglarProducto(billes);
                foreach (var item in bill.BillDetalle)
                {
                    if (item.Id == 0)
                    {
                        GuardarDetalle(item);
                    }
                    else
                    {
                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        if (db.SaveChanges() > 0)
                        {
                            paso1 = true;
                            paso  = true;
                        }
                    }
                }
                if (paso1 == false)
                {
                    if (db.SaveChanges() > 0)
                    {
                        paso = true;
                    }
                }
                BLL.HerramientasBLL.DescontarProductos(Buscar(bill.FacturaId).BillDetalle);

                db.Dispose();
            }
            catch (Exception)
            {
                throw;
            }

            return(paso);
        }
예제 #2
0
        public static void DescontarBuscando(List <FacturaDetalle> facturaDetalles, int id)
        {
            List <FacturaDetalle> detalle = new List <FacturaDetalle>();

            detalle = FacturaDetalleBLL.GetList(x => x.FacturaId == id);
            foreach (var item in detalle)
            {
                foreach (var items in facturaDetalles)
                {
                    if (item.ProductoId == items.ProductoId)
                    {
                        if (item.Cantidad != items.Cantidad)
                        {
                            DescontarProducto(items, item);
                        }
                    }
                }
            }
        }