Initial ...
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Dtos;
|
||||
|
||||
namespace xIds.Providers
|
||||
{
|
||||
public partial class XIdentityManager
|
||||
{
|
||||
#region Admin Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve All UnBanned Users Identifiers
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">caller user identifier</param>
|
||||
/// <returns>a collection of user identifiers</returns>
|
||||
public async Task<ICollection<string>> GetAllUnbanned(
|
||||
ICollection<string> userSelectByParam
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = new List<string>();
|
||||
if (!userSelectByParam.HasChild())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
foreach (var uParam in userSelectByParam)
|
||||
{
|
||||
//
|
||||
var destUser = await ValidateUserExistsAndRetrieve(uParam, checkIsBanned: false);
|
||||
if (!destUser.IsBanned)
|
||||
{
|
||||
result.Add(uParam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get All Banned Users Identifiers
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">caller user identifier</param>
|
||||
/// <returns>a collection of user identifiers</returns>
|
||||
public async Task<ICollection<string>> GetAllBanned(
|
||||
ICollection<string> userSelectByParam
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = new List<string>();
|
||||
if (!userSelectByParam.HasChild())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
foreach (var uParam in userSelectByParam)
|
||||
{
|
||||
//
|
||||
var destUser = await ValidateUserExistsAndRetrieve(uParam, checkIsBanned: false);
|
||||
if (destUser.IsBanned)
|
||||
{
|
||||
result.Add(uParam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ban a Collection of Users
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">caller user identifier</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a collection of user identifiers</returns>
|
||||
public async Task<ICollection<string>> Ban(
|
||||
string userSelectByParam,
|
||||
XUserNameIdRequest model
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider.NotEmpty(userSelectByParam);
|
||||
ValidationProvider.NotNull(model);
|
||||
ValidationProvider.NotZeroChilds(model.Ids);
|
||||
|
||||
//
|
||||
var user = await ValidateUserExistsAndRetrieve(
|
||||
userSelectByParam,
|
||||
forceAdmin: true,
|
||||
checkIsBanned: true,
|
||||
containDetails: false,
|
||||
ignoreDisabledUser: false,
|
||||
checkCanLoginPolicies: true
|
||||
);
|
||||
|
||||
//
|
||||
var result = new List<string>();
|
||||
foreach (var uParam in model.Ids)
|
||||
{
|
||||
//
|
||||
var destUser = await ValidateUserExistsAndRetrieve(uParam, checkIsBanned: false);
|
||||
|
||||
//
|
||||
var isBanned = destUser.IsBanned;
|
||||
if (!isBanned)
|
||||
{
|
||||
//
|
||||
destUser.IsBanned = true;
|
||||
|
||||
//
|
||||
await UpdateUserAsync(
|
||||
user,
|
||||
checkCanLoginPolicies: false,
|
||||
checkIsBanned: false
|
||||
);
|
||||
|
||||
//
|
||||
result.Add(destUser.Id);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnBan a Collection of Users
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">caller user identifier</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a collection of user identifiers</returns>
|
||||
public async Task<ICollection<string>> UnBan(
|
||||
string userSelectByParam,
|
||||
XUserNameIdRequest model
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider.NotEmpty(userSelectByParam);
|
||||
ValidationProvider.NotNull(model);
|
||||
ValidationProvider.NotZeroChilds(model.Ids);
|
||||
|
||||
//
|
||||
var user = await ValidateUserExistsAndRetrieve(
|
||||
userSelectByParam,
|
||||
forceAdmin: true,
|
||||
checkIsBanned: true,
|
||||
containDetails: false,
|
||||
ignoreDisabledUser: false,
|
||||
checkCanLoginPolicies: true
|
||||
);
|
||||
|
||||
//
|
||||
var result = new List<string>();
|
||||
foreach (var uParam in model.Ids)
|
||||
{
|
||||
//
|
||||
var destUser = await ValidateUserExistsAndRetrieve(uParam, checkIsBanned: false);
|
||||
|
||||
//
|
||||
var isBanned = destUser.IsBanned;
|
||||
if (isBanned)
|
||||
{
|
||||
//
|
||||
destUser.IsBanned = false;
|
||||
|
||||
//
|
||||
await UpdateUserAsync(
|
||||
user,
|
||||
checkCanLoginPolicies: false,
|
||||
checkIsBanned: false
|
||||
);
|
||||
|
||||
//
|
||||
result.Add(destUser.Id);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detrmines a User is Banned or not
|
||||
/// </summary>
|
||||
/// <param name="userSelectByParam">caller user identifier</param>
|
||||
/// <param name="destUserSelectByParam">destination user identifier which checked is banned or not</param>
|
||||
/// <returns>a boolean value which represent user banned or not</returns>
|
||||
public async Task<bool> IsBanned(
|
||||
string userSelectByParam,
|
||||
string destUserSelectByParam
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider.NotEmpty(
|
||||
userSelectByParam,
|
||||
destUserSelectByParam
|
||||
);
|
||||
|
||||
//
|
||||
var user = await ValidateUserExistsAndRetrieve(
|
||||
userSelectByParam,
|
||||
forceAdmin: false,
|
||||
checkIsBanned: true,
|
||||
containDetails: false,
|
||||
ignoreDisabledUser: false,
|
||||
checkCanLoginPolicies: true
|
||||
);
|
||||
var destUser = await ValidateUserExistsAndRetrieve(destUserSelectByParam, checkIsBanned: false);
|
||||
|
||||
//
|
||||
var result = destUser.IsBanned;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user