Example #1
0
        public DatatablesDTO GetRoles(string searchValue, string ordering, string column, int start, int length)
        {
            var roles = _roleManager.Roles.Include(r => r.RoleClaims);

            var qry = roles.Where(r =>
                                  (string.IsNullOrWhiteSpace(searchValue) || r.Name.Contains(searchValue))
                                  );

            if (ordering == "asc")
            {
                qry = qry.OrderBy(x => EF.Property <string>(x, Char.ToUpper(column[0]) + column.Substring(1)));
            }
            else
            {
                qry = qry.OrderByDescending(x => EF.Property <string>(x, Char.ToUpper(column[0]) + column.Substring(1)));
            }

            var result = new DatatablesDTO
            {
                recordsTotal    = roles.Count(),
                recordsFiltered = qry.Count(),
                data            = qry.Skip(start).Take(length).ToArray().Select(r => new {
                    Id     = r.Id,
                    Name   = r.Name,
                    Claims = r.RoleClaims.Select(c => new KeyValuePair <string, string>(_claimTypes.Single(x => x.Value == c.ClaimType).Key, c.ClaimValue))
                })
            };

            return(result);
        }
        public IActionResult RoleList(int draw, List <Dictionary <string, string> > columns, List <Dictionary <string, string> > order, int start, int length, Dictionary <string, string> search)
        {
            string searchValue = search["value"];
            var    idx         = int.Parse(order[0]["column"]);
            var    ordering    = order[0]["dir"];
            var    column      = columns[idx]["data"];

            DatatablesDTO data = _identityManagerService.GetRoles(searchValue, ordering, column, start, length);

            data.draw = draw;

            return(Json(data));
        }