Exemplo n.º 1
0
        public bool GuardarDet(List <clsConsolidacionPedidoDet> lista_detalle)
        {
            try
            {
                clsConsolidacionPedidoDet e = new clsConsolidacionPedidoDet();
                int id = getIdSiguiente();
                e.Numero = id - 1;
                using (CompraEntities ent = new CompraEntities())
                { //se instancia el entity para poder usar los nombres de las tablas
                    //se hace el ingreso de cada detalle que existe en la lista
                    int cantidad = lista_detalle.Count();
                    int i        = 0;
                    while (i < cantidad)
                    {
                        e = lista_detalle[i];
                        PedidoDet pedido_detalle = new PedidoDet()
                        {
                            Numero     = e.Numero,
                            idEmpresa  = e.Id_Empresa,
                            Linea      = e.linea,
                            idArticulo = e.Id_articulo,
                            Cantidad   = e.cantidad
                        };

                        ent.AddToPedidoDet(pedido_detalle);
                        ent.SaveChanges();
                        i++;
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error al guardar el detalle de la Solicitud: " + ex);
                return(false);
            }
        }
        public bool GuardarDet(List<clsConsolidacionPedidoDet> lista_detalle)
        {
            try
            {
                clsConsolidacionPedidoDet e = new clsConsolidacionPedidoDet();
                int id = getIdSiguiente();
                e.Numero = id - 1;
                using (CompraEntities ent = new CompraEntities())
                { //se instancia el entity para poder usar los nombres de las tablas

                    //se hace el ingreso de cada detalle que existe en la lista
                    int cantidad = lista_detalle.Count();
                    int i = 0;
                    while (i < cantidad)
                    {
                        e = lista_detalle[i];
                        PedidoDet pedido_detalle = new PedidoDet()
                        {
                            Numero = e.Numero,
                            idEmpresa = e.Id_Empresa,
                            Linea = e.linea,
                            idArticulo = e.Id_articulo,
                            Cantidad = e.cantidad
                        };

                        ent.AddToPedidoDet(pedido_detalle);
                        ent.SaveChanges();
                        i++;
                    }

                }
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error al guardar el detalle de la Solicitud: " + ex);
                return false;
            }
        }