コード例 #1
0
        // GET: WithPagedList
        public ActionResult Index(int?page)
        {
            int pageNumber           = page ?? 1;
            int pageSize             = 10;
            var lstSalesOrderDetails = _salesOrderService.LoadData();

            //var salesList = (from s in lstSalesOrderDetails
            //                orderby s.ProductName
            //                select s).Skip((pageNumber-1)*pageSize).Take(pageSize);
            return(View(lstSalesOrderDetails.ToPagedList(pageNumber, pageSize)));
        }
コード例 #2
0
        public ActionResult getSalesOrders()
        {
            JsonResult result = new JsonResult();

            try
            {
                // Initialization.
                string search   = Request.Form.GetValues("search[value]")[0];
                string draw     = Request.Form.GetValues("draw")[0];
                string order    = Request.Form.GetValues("order[0][column]")[0];
                string orderDir = Request.Form.GetValues("order[0][dir]")[0];
                int    startRec = Convert.ToInt32(Request.Form.GetValues("start")[0]);
                int    pageSize = Convert.ToInt32(Request.Form.GetValues("length")[0]);
                // Loading.
                List <SalesOrderDetail> data = _salesOrderService.LoadData();
                // Total record count.
                int totalRecords = data.Count;
                // Verification.
                if (!string.IsNullOrEmpty(search) &&
                    !string.IsNullOrWhiteSpace(search))
                {
                    // Apply search
                    data = data.Where(p => p.Sr.ToString().ToLower().Contains(search.ToLower()) ||
                                      p.OrderTrackNumber.ToLower().Contains(search.ToLower()) ||
                                      p.Quantity.ToString().ToLower().Contains(search.ToLower()) ||
                                      p.ProductName.ToLower().Contains(search.ToLower()) ||
                                      p.SpecialOffer.ToLower().Contains(search.ToLower()) ||
                                      p.UnitPrice.ToString().ToLower().Contains(search.ToLower()) ||
                                      p.UnitPriceDiscount.ToString().ToLower().Contains(search.ToLower())).ToList();
                }
                // Sorting.
                data = this.SortByColumnWithOrder(order, orderDir, data);
                // Filter record count.
                int recFilter = data.Count;
                // Apply pagination.
                data = data.Skip(startRec).Take(pageSize).ToList();
                // Loading drop down lists.
                result = this.Json(new
                {
                    draw            = Convert.ToInt32(draw),
                    recordsTotal    = totalRecords,
                    recordsFiltered = recFilter,
                    data            = data
                }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }
            // Return info.
            return(result);
        }