Пример #1
0
 public static void AumentarInventario(Ventas ventas)
 {
     try
     {
         foreach (var item in ventas.Detalle)
         {
             ProductosBLL.AumentarInventario(item.ProductoId, item.Cantidad);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #2
0
        private static bool Modificar(Ventas ventas)
        {
            bool     paso = false;
            Contexto db   = new Contexto();

            try
            {
                Ventas anterior = Buscar(ventas.VentaId);

                foreach (var item in anterior.Detalle)
                {
                    var temp = ProductosBLL.Buscar(item.ProductoId);
                    temp.Inventario += item.Cantidad;
                    ProductosBLL.Guardar(temp);
                }

                foreach (var item in ventas.Detalle)
                {
                    if (item.Id == 0)
                    {
                        db.Entry(item).State = EntityState.Added;
                    }
                }

                foreach (var item in anterior.Detalle)
                {
                    if (!ventas.Detalle.Any(A => A.Id == item.Id))
                    {
                        db.Entry(item).State = EntityState.Deleted;
                    }
                }

                db.Entry(ventas).State = EntityState.Modified;
                paso = db.SaveChanges() > 0;


                foreach (var item in ventas.Detalle)
                {
                    var temp = ProductosBLL.Buscar(item.ProductoId);
                    temp.Inventario -= item.Cantidad;
                    ProductosBLL.Guardar(temp);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(paso);
        }
Пример #3
0
        public static bool Insertar(Ventas ventas)
        {
            bool     paso = false;
            Contexto db   = new Contexto();

            try
            {
                db.Ventas.Add(ventas);
                ProductosBLL.DisminuirInventario(ventas);
                paso = (db.SaveChanges() > 0);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }
            return(paso);
        }