public List <hd_ordenes> ValidarOrdenes(DataTable dt)
        {
            List <hd_ordenes> listaordenes = db.hd_ordenes.Take(5000).ToList();
            List <hd_ordenes> listaAgregar = new List <hd_ordenes>();

            foreach (DataRow row in dt.Rows)
            {
                string orden = row[2].ToString().Trim().ToUpper();
                if (listaordenes.Where(x => x.NumeroOrden.Equals(orden)).FirstOrDefault() == null)
                {
                    if (listaAgregar.Where(x => x.NumeroOrden == orden).FirstOrDefault() == null)
                    {
                        hd_ordenes ordenes = new hd_ordenes();
                        ordenes.NumeroOrden           = orden;
                        ordenes.OracleID              = row[3].ToString().Trim().ToUpper();
                        ordenes.Guia                  = row[4].ToString().Trim().ToUpper();
                        ordenes.Paquetes              = 1;
                        ordenes.FechaAlta             = DateTime.Now;
                        ordenes.Pickers_Id            = 1;
                        ordenes.Auditores_Id          = 1;
                        ordenes.hd_statusorden_Id     = 1;
                        ordenes.hd_statusquickship_Id = 1;
                        ordenes.Empleados_Id          = 1;

                        listaAgregar.Add(ordenes);
                    }
                }
            }

            db.hd_ordenes.AddRange(listaAgregar);
            db.SaveChanges();
            return(listaAgregar);
        }
        public ActionResult ObtenerOrdenes()
        {
            try
            {
                var Draw          = Request.Form.GetValues("draw").FirstOrDefault();
                var Start         = Request.Form.GetValues("start").FirstOrDefault();
                var Length        = Request.Form.GetValues("length").FirstOrDefault();
                var SortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][data]").FirstOrDefault();
                var SortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();

                var orden = Request.Form.GetValues("columns[0][search][value]").FirstOrDefault();

                int PageSize = Length != null?Convert.ToInt32(Length) : 0;

                int Skip = Start != null?Convert.ToInt32(Start) : 0;

                int TotalRecords = 0;

                List <hd_ordenes> lista = new List <hd_ordenes>();

                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionGlobal"].ToString()))
                {
                    con.Open();

                    string sql   = "exec SP_Ordenes_Index @orden";
                    var    query = new SqlCommand(sql, con);

                    if (orden != "")
                    {
                        query.Parameters.AddWithValue("@orden", orden);
                    }
                    else
                    {
                        query.Parameters.AddWithValue("@orden", DBNull.Value);
                    }

                    using (var dr = query.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            // facturas
                            var ordenesTemp = new hd_ordenes();

                            ordenesTemp.Id          = Convert.ToInt32(dr["Id"]);
                            ordenesTemp.NumeroOrden = dr["NumeroOrden"].ToString();
                            ordenesTemp.Guia        = dr["Guia"].ToString();
                            ordenesTemp.OracleID    = dr["OracleID"].ToString();
                            ordenesTemp.Paquetes    = Convert.ToInt32(dr["Paquetes"]);
                            ordenesTemp.status      = dr["Descripcion"].ToString();

                            lista.Add(ordenesTemp);
                        }
                    }
                }

                if (!(string.IsNullOrEmpty(SortColumn) && string.IsNullOrEmpty(SortColumnDir)))
                {
                    lista = lista.OrderBy(SortColumn + " " + SortColumnDir).ToList();
                }

                TotalRecords = lista.ToList().Count();
                var NewItems = lista.Skip(Skip).Take(PageSize == -1 ? TotalRecords : PageSize).ToList();

                return(Json(new { draw = Draw, recordsFiltered = TotalRecords, recordsTotal = TotalRecords, data = NewItems }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                throw;
            }
        }