コード例 #1
0
        public dynamic GetList(string _search, long nd, int rows, int?page, string sidx, string sord, string filters = "")
        {
            // Construct where statement

            string strWhere = GeneralFunction.ConstructWhere(filters);

            // Get Data
            var query = _cashBankService.GetAll().Where(d => d.IsDeleted == false);

            var list = query as IEnumerable <CashBank>;

            var pageIndex    = Convert.ToInt32(page) - 1;
            var pageSize     = rows;
            var totalRecords = query.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            // default last page
            if (totalPages > 0)
            {
                if (!page.HasValue)
                {
                    pageIndex = totalPages - 1;
                    page      = totalPages;
                }
            }

            list = list.Skip(pageIndex * pageSize).Take(pageSize);

            return(Json(new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from item in list
                    select new
                {
                    id = item.Id,
                    cell = new object[] {
                        item.Id,
                        item.Name,
                        item.Description,
                        item.Amount,
                        item.CreatedAt,
                        item.UpdatedAt,
                    }
                }).ToArray()
            }, JsonRequestBehavior.AllowGet));
        }