Compare commits
10
Commits
e7979f8a65
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
313897e911 | ||
|
|
2546e7cb2c | ||
|
|
e2e15810fc | ||
|
|
ae4ad277d1 | ||
|
|
4580e71c7b | ||
|
|
6c2d1a7e00 | ||
|
|
672de1e720 | ||
|
|
d4ea1d63cf | ||
|
|
1b861b3e99 | ||
|
|
0040203921 |
+1
-1
@@ -2,7 +2,7 @@ using System.Collections.Generic;
|
||||
using xDataService.Constants;
|
||||
using xStringService.Models.Dtos;
|
||||
|
||||
namespace xTermsAndConditionsService.Configuration
|
||||
namespace xTermsAndConditionsService.Configurations
|
||||
{
|
||||
/// <summary>
|
||||
/// Terms and Conditions Configuration ...
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace xTermsAndConditionsService.Constants
|
||||
{
|
||||
public struct XTermsAndConditionsServiceConstants
|
||||
{
|
||||
//
|
||||
// Service Extensions Log Tag ...
|
||||
public const string XTermsAndConditionsServiceDILogTag = "XTermsAndConditionsService";
|
||||
|
||||
//
|
||||
// Table Mapping Identifiers ...
|
||||
|
||||
//
|
||||
// GraphQL Collection Mappings ...
|
||||
|
||||
//
|
||||
// Hubs ...
|
||||
|
||||
//
|
||||
// Custome Constants ...
|
||||
|
||||
//
|
||||
// EF Repositories Helper Extensions ...
|
||||
}
|
||||
}
|
||||
@@ -1,313 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Base;
|
||||
using xTermsAndConditionsService.Interfaces;
|
||||
|
||||
namespace xTermsAndConditionsService.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// a Base Controller Implementation for Providing Base Actions of
|
||||
/// Terms and Conditions Provided Actions ...
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
public abstract class XTermsAndComditionsControllerBase : XBaseIdentityApiV1Controller, IXTermsAndComditionsController
|
||||
{
|
||||
private readonly IXTermsAndComditionsProvider provider;
|
||||
|
||||
protected XTermsAndComditionsControllerBase(
|
||||
ILogger<XTermsAndComditionsControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
IXTermsAndComditionsProvider provider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Retrieved all Exists Languages Terms and Conditions ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Terms/Languages")]
|
||||
public virtual async Task<ActionResult<IEnumerable<string>>> TermsLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await provider.TermsLanguages(
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Has Terms and Conditions based on Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Terms/{language}/Has")]
|
||||
public virtual async Task<ActionResult<bool>> HasTerms(
|
||||
[FromRoute] string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(language)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var result = await provider.HasTerms(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Terms/{language}")]
|
||||
public virtual async Task<ActionResult<string>> GetTerms(
|
||||
[FromRoute] string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(language)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var result = await provider.GetTerms(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Terms/{language}")]
|
||||
public virtual async Task<ActionResult<string>> AddTerms(
|
||||
[FromRoute] string language,
|
||||
[FromBody] XBaseValueContainer<string> terms,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(language)
|
||||
.AddNotNull(terms)
|
||||
.AddNotEmpty(terms.Value)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await provider.AddTerms(
|
||||
language: language,
|
||||
terms: terms.Value,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("Terms/{language}")]
|
||||
public virtual async Task<ActionResult<bool>> RemoveTerms(
|
||||
[FromRoute] string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(language)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await provider.RemoveTerms(
|
||||
language: language,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("Terms/{language}")]
|
||||
public virtual async Task<ActionResult<bool>> UpdateTerms(
|
||||
[FromRoute] string language,
|
||||
[FromBody] XBaseValueContainer<string> terms,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(language)
|
||||
.AddNotNull(terms)
|
||||
.AddNotEmpty(terms.Value)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await provider.UpdateTerms(
|
||||
language: language,
|
||||
terms: terms.Value,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xStringService.Controllers;
|
||||
using xTermsAndConditionsService.Interfaces;
|
||||
|
||||
namespace xTermsAndConditionsService.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// a Base Controller Implementation for Providing Base Actions of
|
||||
/// Terms and Conditions Provided Actions ...
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
public abstract class XTermsAndConditionsControllerBase : XBaseResourceProviderControllerBase<IXTermsAndConditionsProvider>, IXTermsAndConditionsController
|
||||
{
|
||||
protected XTermsAndConditionsControllerBase(
|
||||
ILogger<XTermsAndConditionsControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXTermsAndConditionsProvider provider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
provider
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using xExceptions.Constants;
|
||||
using xPushService.DI;
|
||||
using xPushService.Helpers;
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xTermsAndConditionsService.Configuration;
|
||||
using xTermsAndConditionsService.Configurations;
|
||||
using xTermsAndConditionsService.Constants;
|
||||
using xTermsAndConditionsService.Hubs;
|
||||
using xTermsAndConditionsService.Interfaces;
|
||||
@@ -129,7 +129,7 @@ namespace xTermsAndConditionsService.DI
|
||||
//
|
||||
// Using XTerms Hub ...
|
||||
var pushHelper = new XPushServiceHelper();
|
||||
pushHelper.AddHub<XTermsHub>("termsHub");
|
||||
pushHelper.AddHub<XTermsHub>("terms");
|
||||
app.UseXPushService(pushHelper);
|
||||
|
||||
//
|
||||
@@ -214,7 +214,7 @@ namespace xTermsAndConditionsService.DI
|
||||
/// <summary>
|
||||
/// a LogTag for Service ...
|
||||
/// </summary>
|
||||
private static string XLogTag = "XTermsAndConditionsService";
|
||||
private static string XLogTag = XTermsAndConditionsServiceConstants.XTermsAndConditionsServiceDILogTag;
|
||||
|
||||
/// <summary>
|
||||
/// print a log in Console ...
|
||||
@@ -294,7 +294,7 @@ namespace xTermsAndConditionsService.DI
|
||||
|
||||
//
|
||||
// Register Resource Providers ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXTermsAndComditionsProvider), typeof(XTermsAndComditionsProvider), lifeTime));
|
||||
services.Add(new ServiceDescriptor(typeof(IXTermsAndConditionsProvider), typeof(XTermsAndConditionsProvider), lifeTime));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xModels.Base;
|
||||
|
||||
namespace xTermsAndConditionsService.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// an Interface for Describing Terms and Conditions Management Controller Actions ...
|
||||
/// </summary>
|
||||
public interface IXTermsAndComditionsController
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieved all Exists Languages Terms and Conditions ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Terms/Languages")]
|
||||
Task<ActionResult<IEnumerable<string>>> TermsLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Check Has Terms and Conditions based on Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Terms/{language}/Has")]
|
||||
Task<ActionResult<bool>> HasTerms(
|
||||
[FromRoute] string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Terms/{language}")]
|
||||
Task<ActionResult<string>> GetTerms(
|
||||
[FromRoute] string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Terms/{language}")]
|
||||
Task<ActionResult<string>> AddTerms(
|
||||
[FromRoute] string language,
|
||||
[FromBody] XBaseValueContainer<string> terms,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("Terms/{language}")]
|
||||
Task<ActionResult<bool>> RemoveTerms(
|
||||
[FromRoute] string language,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Update Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("Terms/{language}")]
|
||||
Task<ActionResult<bool>> UpdateTerms(
|
||||
[FromRoute] string language,
|
||||
[FromBody] XBaseValueContainer<string> terms,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xIdentityModels.Models;
|
||||
|
||||
namespace xTermsAndConditionsService.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// an Interface for Describing Terms and Conditions Management Provided Actions ...
|
||||
/// </summary>
|
||||
public interface IXTermsAndComditionsProvider
|
||||
{
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Retrieved all Exists Languages Terms and Conditions ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> TermsLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Check Has Terms and Conditions based on Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> HasTerms(
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetTerms(
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> AddTerms(
|
||||
string language,
|
||||
string terms,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> RemoveTerms(
|
||||
string language,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Update Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateTerms(
|
||||
string language,
|
||||
string terms,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using xStringService.Interfaces;
|
||||
|
||||
namespace xTermsAndConditionsService.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// an Interface for Describing Terms and Conditions Management Controller Actions ...
|
||||
/// </summary>
|
||||
public interface IXTermsAndConditionsController : IXBaseResourceProviderController
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using xStringService.Interfaces;
|
||||
|
||||
namespace xTermsAndConditionsService.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// an Interface for Describing Terms and Conditions Management Provided Actions ...
|
||||
/// </summary>
|
||||
public interface IXTermsAndConditionsProvider : IXResourceProvider
|
||||
{ }
|
||||
}
|
||||
@@ -1,495 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Extensions;
|
||||
using xIdentityModels.Models;
|
||||
using xPushService.Constants;
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
using xTermsAndConditionsService.Configuration;
|
||||
using xTermsAndConditionsService.Hubs;
|
||||
using xTermsAndConditionsService.Interfaces;
|
||||
|
||||
namespace xTermsAndConditionsService.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// an Implementation of Terms and Conditions Management Provided Actions ...
|
||||
/// </summary>
|
||||
public class XTermsAndComditionsProvider : IXTermsAndComditionsProvider
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
private readonly string termsId;
|
||||
private readonly string[] allowedRoles;
|
||||
private readonly IHubContext<XTermsHub> hub;
|
||||
private readonly XAppConfiguration appConfiguration;
|
||||
private readonly IXStringServiceProvider stringProvider;
|
||||
private readonly XTermsAndConditionsServiceConfiguration serviceConfiguration;
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XTermsAndComditionsProvider(
|
||||
XAppConfiguration appConfiguration,
|
||||
IXStringServiceProvider stringProvider,
|
||||
XTermsAndConditionsServiceConfiguration serviceConfiguration,
|
||||
IHubContext<XTermsHub> hub = null
|
||||
)
|
||||
{
|
||||
//
|
||||
this.hub = hub;
|
||||
this.stringProvider = stringProvider;
|
||||
this.appConfiguration = appConfiguration;
|
||||
this.serviceConfiguration = serviceConfiguration;
|
||||
|
||||
//
|
||||
termsId = serviceConfiguration.ResourceTitle;
|
||||
|
||||
//
|
||||
// Specified roles for Handling Dangerouse Actions ...
|
||||
this.allowedRoles = new string[]
|
||||
{
|
||||
"admin"
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Retrieved all Exists Languages Terms and Conditions ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<string>> TermsLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await stringProvider
|
||||
.FindManyAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.ResourceTitle == termsId,
|
||||
orderBuilder: x => x.OrderBy(y => y.ResourceTitle)
|
||||
))
|
||||
.Select(x => x.Language);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Has Terms and Conditions based on Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> HasTerms(
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Normalize ...
|
||||
if (language.IsNullOrEmpty())
|
||||
{
|
||||
language = appConfiguration.DefaultLanguage;
|
||||
}
|
||||
|
||||
//
|
||||
var result = !(await GetString(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
))
|
||||
.IsNullOrDefault();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">if null, used Default Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetTerms(
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = string.Empty;
|
||||
var item = await GetString(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
if (!item.IsNullOrDefault())
|
||||
{
|
||||
result = item.TranslatedValue;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Terms and Conditions for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> AddTerms(
|
||||
string language,
|
||||
string terms,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
!language.IsNullOrEmpty() &&
|
||||
!terms.IsNullOrEmpty() &&
|
||||
!userInfo.IsNullOrDefault() &&
|
||||
language != appConfiguration.DefaultLanguage;
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
isValid = await HasTerms(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (isValid)
|
||||
{
|
||||
XException.Duplicate.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Permission ...
|
||||
isValid = userInfo.HasAccess(allowedRoles);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Add Terms ...
|
||||
XStringDto item = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
item = new XStringDto
|
||||
{
|
||||
Language = language,
|
||||
ResourceTitle = termsId,
|
||||
TranslatedValue = terms,
|
||||
};
|
||||
item = await stringProvider.AddAsync(
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
catch { }
|
||||
|
||||
//
|
||||
var result = string.Empty;
|
||||
if (!item.IsNullOrDefault())
|
||||
{
|
||||
result = item.TranslatedValue;
|
||||
}
|
||||
|
||||
//
|
||||
if (!result.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
payLoad: item.ToJSON(camelCase: true),
|
||||
action: XBaseEntityHubAction.Add.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemoveTerms(
|
||||
string language,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var isValid =
|
||||
!language.IsNullOrEmpty() &&
|
||||
!userInfo.IsNullOrDefault() &&
|
||||
language != appConfiguration.DefaultLanguage;
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
var item = await GetString(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
isValid = !item.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Permission ...
|
||||
isValid = userInfo.HasAccess(allowedRoles);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
item = await stringProvider.RemoveAsync(
|
||||
id: item.Id,
|
||||
softDelete: false,
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
item = null;
|
||||
}
|
||||
|
||||
//
|
||||
var result = !item.IsNullOrDefault();
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
payLoad: item.ToJSON(camelCase: true),
|
||||
action: XBaseEntityHubAction.Delete.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Terms and Conditions of Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="terms"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateTerms(
|
||||
string language,
|
||||
string terms,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var isValid =
|
||||
!terms.IsNullOrEmpty() &&
|
||||
!language.IsNullOrEmpty() &&
|
||||
!userInfo.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
var item = await GetString(
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
isValid = !item.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Permission ...
|
||||
isValid = userInfo.HasAccess(allowedRoles);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
item.TranslatedValue = terms;
|
||||
item = await stringProvider.UpdateAsync(
|
||||
id: item.Id,
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
item = null;
|
||||
}
|
||||
|
||||
//
|
||||
var result = !item.IsNullOrDefault();
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
payLoad: item.ToJSON(camelCase: true),
|
||||
action: XBaseEntityHubAction.Update.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Hub Actions ...
|
||||
/// <summary>
|
||||
/// Send Custom Push Message ...
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="payLoad"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SendPush(
|
||||
string action,
|
||||
string payLoad,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var actions = new List<string>
|
||||
{
|
||||
XBaseEntityHubAction.Add.GetStringValue(),
|
||||
XBaseEntityHubAction.Update.GetStringValue(),
|
||||
XBaseEntityHubAction.Delete.GetStringValue(),
|
||||
};
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
!hub.IsNull() &&
|
||||
!action.IsNullOrEmpty() &&
|
||||
actions.Contains(action);
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var clients = hub.Clients.All;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
clients = hub.Clients.AllExcept(connectionId);
|
||||
}
|
||||
try
|
||||
{
|
||||
//
|
||||
await clients.SendAsync(
|
||||
action,
|
||||
payLoad,
|
||||
connectionId,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// Retrieve Terms and Conditions XString Entity ...
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XStringDto> GetString(
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Normalize ...
|
||||
if (language.IsNullOrEmpty())
|
||||
{
|
||||
language = appConfiguration.DefaultLanguage;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve ...
|
||||
XStringDto result = null;
|
||||
try
|
||||
{
|
||||
//
|
||||
result = await stringProvider.FindOneAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
predicate: x =>
|
||||
x.Language == language &&
|
||||
x.ResourceTitle == termsId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xStringService.Providers;
|
||||
using xTermsAndConditionsService.Configurations;
|
||||
using xTermsAndConditionsService.Interfaces;
|
||||
|
||||
namespace xTermsAndConditionsService.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// an Implementation of Terms and Conditions Management Provided Actions ...
|
||||
/// </summary>
|
||||
public class XTermsAndConditionsProvider : XBaseResourceProvider, IXTermsAndConditionsProvider
|
||||
{
|
||||
public XTermsAndConditionsProvider(
|
||||
IXStringServiceProvider provider,
|
||||
XTermsAndConditionsServiceConfiguration configuration
|
||||
) : base(
|
||||
resource: "NULL",
|
||||
provider
|
||||
)
|
||||
{
|
||||
//
|
||||
// Since we nee to Set Resource Title of Terms and Conditions
|
||||
// during instancing using Provided Configurations ...
|
||||
// set this value here ...
|
||||
resource = configuration.ResourceTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
it is a Part of xDashboard on SaherElm IT Center which provides Terms and Conditions Management Futures ...
|
||||
|
||||
its depends on:
|
||||
this module has following dependencies :
|
||||
|
||||
- **xStringService**
|
||||
|
||||
for configure and use this Module refer to DI.XDIHelperExtension.cs file.
|
||||
|
||||
## Providers
|
||||
|
||||
in this module all requirements tools for manage Terms and Conditions Integrated and Provided.
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
<!-- Runtime Definition -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>xDashboard.xTermsAndConditionsService</PackageId>
|
||||
<Version>1.0.0</Version>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<Authors>Hadi Khazaee Asl</Authors>
|
||||
<Company>SaherElm IT Center</Company>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>xDashboard.xTermsAndConditionsService</PackageId>
|
||||
|
||||
<Description>
|
||||
it is a Part of xDashboard on SaherElm IT Center which provides Terms and Conditions Management Futures ...
|
||||
it is a Part of xDashboard on SaherElm IT Center which provides Terms and Conditions
|
||||
Management Futures ...
|
||||
</Description>
|
||||
|
||||
<!-- Icon Definition -->
|
||||
@@ -17,7 +20,8 @@
|
||||
|
||||
<!-- Icon Handling -->
|
||||
<ItemGroup>
|
||||
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true" PackagePath="\icon.png" />
|
||||
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true"
|
||||
PackagePath="\icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Local Modules -->
|
||||
@@ -30,4 +34,11 @@
|
||||
<ProjectReference Include="../xStringService/xStringService.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- For XML Documentation Support -->
|
||||
<PropertyGroup>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user