示例#1
0
        public ActionResult searchPrecioConsignadoMateria()
        {
            var draw   = Request.Form.GetValues("draw").FirstOrDefault();
            var start  = Request.Form.GetValues("start").FirstOrDefault();
            var lenght = Request.Form.GetValues("length").FirstOrDefault();

            var sortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();

            var searchv  = Request.Form.GetValues("search[value]").FirstOrDefault();
            int pagesize = lenght != null?Convert.ToInt32(lenght) : 0;

            int skip = start != null?Convert.ToInt32(start) : 0;

            int totalRecords = 0;


            if (searchv.ToString().Equals(""))
            {
                searchv = "-1";
            }

            using (db)
            {
                var v2 = (from a in db.fn_ObtenerMIPrecioConsignado(Convert.ToInt16(searchv)) select a);
                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                {
                    v2 = v2.OrderBy(sortColumn + " " + sortColumnDir);
                }

                totalRecords = v2.Count();
                var data = v2.Skip(skip).Take(pagesize).ToList();
                return(Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet));
            }
        }