Initial ...
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Dtos;
|
||||
using xModels.Dtos;
|
||||
using xDataService.Extensions;
|
||||
using xIds.Extensions;
|
||||
using System.Linq;
|
||||
using xIdentityModels.Extensions;
|
||||
|
||||
namespace xIds.Providers
|
||||
{
|
||||
public partial class XIdentityManager
|
||||
{
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Query User Profiles
|
||||
/// </summary>
|
||||
/// <param name="requestedUserSelectByParam">requested user's identifier</param>
|
||||
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
||||
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
|
||||
public async Task<XQueryResult<XUserProfileDto>> QueryOpenToSearchUsers(
|
||||
string requestedUserSelectByParam,
|
||||
XQuery query
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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 totalEntities = GetUsersDbSet()
|
||||
.Where(u => u.OpenToSearch)
|
||||
.ToList()
|
||||
.Where(u => !u.ContainsUserSelectByParam(requestedUserSelectByParam))
|
||||
.Select(u => u.Id)
|
||||
.ToList();
|
||||
|
||||
//
|
||||
var items = await GetUserProfilesAsync(
|
||||
totalEntities,
|
||||
requestedUserSelectByParam,
|
||||
checkIsBanned: false,
|
||||
checkCanLoginPolicies: false,
|
||||
forceCheckRequestedUser: false
|
||||
);
|
||||
|
||||
//
|
||||
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<XUserProfileDto>
|
||||
{
|
||||
Items = items,
|
||||
Page = query.Page,
|
||||
PageSize = query.PageSize,
|
||||
TotalPages = totalPagesCount,
|
||||
TotalItems = totalItemsCount,
|
||||
TotalFilteredPages = filteredPagesCount,
|
||||
TotalFilteredItems = filteredItemsCount
|
||||
};
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user