public IActionResult GetAccounts([FromBody] DataTableAjaxPostModel model)
        {
            if (!_currentUser.HasRole(Permission.UserAccountViewer, Permission.UserAccountAdmin))
            {
                return(Forbidden());
            }

            _logger.LogInformation("Retrieving user accounts for search");
            _logger.LogDebug("Request body: {0}", JsonSerializer.Serialize(model));

            Specification <AppUser> spec = string.IsNullOrWhiteSpace(model.Search.Value) ? Specification <AppUser> .All : Specification <AppUser> .None;

            string[] searchTerms = model.Search.Value.Split(" ", StringSplitOptions.RemoveEmptyEntries);
            foreach (string term in searchTerms)
            {
                if (Email.Create(term).IsSuccess) // search term is an email address
                {
                    spec = spec.Or(new UserAccountWithUsernameSpec(term));
                }
                else
                {
                    spec = spec.Or(new UserAccountWithNameLikeSpec(term));
                }
            }

            AppUserSortableColumn sortBy = AppUserSortableColumn.Id;
            bool sortDir = true;

            List <AppUser> appUsers = _appUserRepo.GetList(spec,
                                                           take: model.Length,
                                                           skip: model.Start,
                                                           filteredResultsCount: out int filteredResultsCount,
                                                           totalResultsCount: out int totalResultsCount,
                                                           sortBy: sortBy,
                                                           sortDir: sortDir).ToList();

            var result = appUsers.Select(d => new UserAccountSummaryDTO
            {
                Id                    = d.Id,
                FirstName             = d.FirstName,
                LastName              = d.LastName,
                Username              = d.Username,
                AccessFailedCount     = d.AccessFailedCount,
                LockoutEnabled        = d.LockoutEnabled,
                LockoutEndDateTimeUtc = d.LockoutEndDateTimeUtc?.ToString("yyyy-MM-dd hh:mm tt"),
                DateTimeRegistered    = d.CreatedDateTimeUtc?.ToLocalTime().ToString("yyyy-MM-dd hh:mm tt")
            });

            return(Ok(new DataTableAjaxPostResponse <UserAccountSummaryDTO>
            {
                Draw = model.Draw,
                RecordsTotal = totalResultsCount,
                RecordsFiltered = filteredResultsCount,
                Data = result
            }, contextReadonly: true));
        }
        public IReadOnlyCollection <AppUser> GetList(
            Specification <AppUser> spec,
            out int filteredResultsCount,
            out int totalResultsCount,
            int take = 10,
            int skip = 0,
            AppUserSortableColumn sortBy = AppUserSortableColumn.Id,
            bool sortDir = true)
        {
            totalResultsCount = _unitOfWork.Query <AppUser>().Count(); // total entries in table
            IQueryable <AppUser> filteredResult = _unitOfWork.Query <AppUser>()
                                                  .Where(spec.ToExpression())
                                                  .AsQueryable();

            filteredResultsCount = filteredResult.Count(); // available result count for query

            return(filteredResult
                   .OrderBy(sortBy.ToString(), sortDir)
                   .Skip(skip)
                   .Take(take)
                   .ToList()
                   .AsReadOnly());
        }