Initial Commit ...
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Dtos;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIdentityService.Providers {
|
||||
public partial class XIdentityProvider {
|
||||
//
|
||||
#region Admin ...
|
||||
/// <summary>
|
||||
/// Ban Specific Users
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a list of banned users identifiers</returns>
|
||||
public async Task<IEnumerable<string>> Ban (
|
||||
XTokenResponse tokens,
|
||||
XUserNameIdRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
tokens,
|
||||
model
|
||||
)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.AddNotZeroChilds (model.Ids)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.Ban);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnBann Specific Users
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="model">an instance of <see>XUserNameIdRequest</see> which represents user identifier list to Ban</param>
|
||||
/// <returns>a list of unbanned users identifiers</returns>
|
||||
public async Task<IEnumerable<string>> UnBan (
|
||||
XTokenResponse tokens,
|
||||
XUserNameIdRequest model
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (
|
||||
tokens,
|
||||
model
|
||||
)
|
||||
.AddNotEmpty (tokens.AccessToken)
|
||||
.AddNotZeroChilds (model.Ids)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (XApiAccountEndpoint.UnBan);
|
||||
request.AddJsonBody (model);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<IEnumerable<string>> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.POST
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Specific User is Banned or not
|
||||
/// </summary>
|
||||
/// <param name="tokens">Authentication Tokens</param>
|
||||
/// <param name="userSelectByParam">specified user's identifier</param>
|
||||
/// <returns>a boolean value which represent user banned or not</returns>
|
||||
public async Task<bool> IsBanned (
|
||||
XTokenResponse tokens,
|
||||
string userSelectByParam
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
await validationProvider
|
||||
.GroupValidationBuilder ()
|
||||
.AddNotNull (tokens)
|
||||
.AddNotEmpty (
|
||||
userSelectByParam,
|
||||
tokens.AccessToken
|
||||
)
|
||||
.ValidateGroupAsync ();
|
||||
|
||||
//
|
||||
var client = GetRestClient (tokens);
|
||||
|
||||
//
|
||||
var request = GetRestRequet (
|
||||
XApiAccountEndpoint.IsBanned,
|
||||
@params : new Dictionary<string, string> { { XParam.XUserSelectByParam.GetStringValue (), userSelectByParam } }
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<bool> (
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user