110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using xCommons.Extensions;
|
|
using xExceptions.Constants;
|
|
using xDataService.Extensions;
|
|
using xIds.Extensions;
|
|
using xModels.Dtos;
|
|
using xIdentityModels.Extensions;
|
|
|
|
namespace xIds.Providers
|
|
{
|
|
public partial class XIdentityManager
|
|
{
|
|
/// <summary>
|
|
/// Retrieve Users as Query Model for Query Service ...
|
|
/// </summary>
|
|
/// <param name="requestedUserSelectByParam"></param>
|
|
/// <param name="query"></param>
|
|
/// <param name="role"></param>
|
|
/// <param name="forceRole"></param>
|
|
/// <returns></returns>
|
|
public async Task<XQueryResult<string>> QueryUsers(
|
|
string requestedUserSelectByParam,
|
|
XQuery query,
|
|
string role = null,
|
|
bool forceRole = false
|
|
)
|
|
{
|
|
//
|
|
// Validation ...
|
|
if (query.IsNull())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
// Normalize ...
|
|
query = query.NormalizeQuery(DataConfiguration.ToXDataServiceConfig());
|
|
|
|
//
|
|
// Since in Resourceable Entities we have to Search on Locales
|
|
// we Must Implement Senario Custom ...
|
|
var items = GetUsersDbSet()
|
|
.ToList()
|
|
.Where(u => !u.ContainsUserSelectByParam(requestedUserSelectByParam))
|
|
.ToList()
|
|
.AsEnumerable();
|
|
|
|
//
|
|
var totalItemsCount = items.Count();
|
|
|
|
//
|
|
// Apply Filter ...
|
|
if (!query.Filter.IsNullOrEmpty())
|
|
{
|
|
//
|
|
items = items
|
|
.ApplyFilter(query.Filter);
|
|
}
|
|
int filteredItemsCount = items.Count();
|
|
|
|
//
|
|
// Count Pages ...
|
|
var totalPagesCount = query.CountPages(totalItemsCount);
|
|
var filteredPagesCount = query.CountPages(filteredItemsCount);
|
|
|
|
//
|
|
// Apply Paging and Sorting ...
|
|
if (totalItemsCount > 0 &&
|
|
filteredItemsCount > 0)
|
|
{
|
|
//
|
|
// Apply Sorting ...
|
|
items = items
|
|
.ToList()
|
|
.ApplySorting(
|
|
query.SortBy,
|
|
query.IsAscending
|
|
);
|
|
|
|
//
|
|
// Apply Paging ...
|
|
items = items
|
|
.ToList()
|
|
.ApplyPaging(
|
|
query.Page,
|
|
query.PageSize
|
|
);
|
|
}
|
|
|
|
//
|
|
// Generate Result Object ...
|
|
// Query = query,
|
|
var result = new XQueryResult<string>
|
|
{
|
|
Items = items
|
|
.Select(u => u.Id),
|
|
Page = query.Page,
|
|
PageSize = query.PageSize,
|
|
TotalPages = totalPagesCount,
|
|
TotalItems = totalItemsCount,
|
|
TotalFilteredPages = filteredPagesCount,
|
|
TotalFilteredItems = filteredItemsCount
|
|
};
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
} |