public void DescontarProductosDeLote(int idLote, int pCantidadADescontar, int idVenta)
 {
     using (var repo = new Repositorio())
     {
         repo.Lotes.Find(idLote).CantidadProductos -= pCantidadADescontar;
         Venta       venta       = repo.Ventas.Find(idVenta);
         Lote        lote        = repo.Lotes.Find(idLote);
         LoteVendido loteVendido = new LoteVendido(venta, lote);
         loteVendido.Cantidad = pCantidadADescontar;
         repo.LoteVendidos.Add(loteVendido);
         repo.SaveChanges();
     }
 }
Esempio n. 2
0
        public void RestaurarStock(long IdPxv)
        {
            List <LoteVendido> lotesv = new List <LoteVendido>();
            LoteVendido        lotev;
            LoteNegocio        negL = new LoteNegocio();
            Lote     lote;
            AccesoDB conexion = null;

            try
            {
                conexion = new AccesoDB();
                conexion.SetearConsulta("SELECT IDLOTE, CANTIDAD FROM LOTES_X_VENTA WHERE IDPXV = @idpxv");
                conexion.Comando.Parameters.Clear();
                conexion.Comando.Parameters.AddWithValue("@idpxv", IdPxv);

                conexion.AbrirConexion();
                conexion.EjecutarConsulta();

                while (conexion.Lector.Read())
                {
                    lotev = new LoteVendido
                    {
                        IdPxv    = IdPxv,
                        IdLote   = (long)conexion.Lector[0],
                        Cantidad = (int)conexion.Lector[1]
                    };
                    lotesv.Add(lotev);
                }

                foreach (LoteVendido lv in lotesv)
                {
                    lote            = negL.ObtenerLote(lv.IdLote);
                    lote.UnidadesE += lv.Cantidad;
                    negL.ModificarStock(lote.IdLote, lote.UnidadesE);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conexion.CheckearConexion() == true)
                {
                    conexion.CerrarConexion();
                }
            }
        }
Esempio n. 3
0
        public void AgregarLoteVendido(int pIdLote, int pIdVenta, int pCantidad)
        {
            using (var repo = new Repositorio())
            {
                var lote  = repo.Lotes.Find(pIdLote);
                var venta = repo.Ventas.Find(pIdVenta);

                if ((lote == null) || (venta == null))
                {
                    throw new Exception("Lote o venta son null");
                }
                var loteVendido = new LoteVendido();
                loteVendido.Lote     = lote;
                loteVendido.Venta    = venta;
                loteVendido.Cantidad = pCantidad;
                repo.SaveChanges();
            }
        }