Esempio n. 1
0
        public virtual JsonResult RolesDynamicGridData(int id, int page, int rows, String search, String sidx, String sord)
        {
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = rows;
            var userGroup = userGroupService.Find(id);

            if (userGroup == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Translate("Messages.CouldNotFoundEntity"));
            }
            ICriteria searchCriteria = roleLocaleService.GetSearchCriteriaForAssign(search);
            long      totalRecords   = roleLocaleService.Count(searchCriteria);
            var       totalPages     = (int)Math.Ceiling((float)totalRecords / pageSize);
            var       roles          = searchCriteria.SetMaxResults(pageSize).SetFirstResult(pageIndex * pageSize).AddOrder(sord == "asc" ? Order.Asc(sidx) : Order.Desc(sidx)).List <RoleLocale>();
            var       jsonData       = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows    = (
                    from role in roles
                    select new
                {
                    id = role.Role.Id,
                    cell = new[] { role.Role.Name }
                }).ToArray()
            };

            return(Json(jsonData));
        }