244 lines
7.0 KiB
C#
244 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xCommons.Extensions;
|
|
using xIdentityHelper;
|
|
using xServices.TermsConditions.Interfaces;
|
|
|
|
namespace xApi.Controllers.V1
|
|
{
|
|
/// <summary>
|
|
/// Implementing Terms and Conditions Action Provider ...
|
|
/// </summary>
|
|
public partial class ConfigurationsController : IXTermsConditionsControllerActions
|
|
{
|
|
//
|
|
#region Actions ...
|
|
/// <summary>
|
|
/// Retrieved all Exists Languages Terms and Conditions ...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("Terms/Languages")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<IEnumerable<string>>> TermsLanguages()
|
|
{
|
|
//
|
|
// Do ...
|
|
try
|
|
{
|
|
//
|
|
// Retrieve User Info ...
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await TermsProvider.TermsLanguages();
|
|
|
|
//
|
|
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")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public async Task<ActionResult<bool>> HasTerms(
|
|
[FromRoute] string language = null
|
|
)
|
|
{
|
|
//
|
|
// Do ...
|
|
try
|
|
{
|
|
//
|
|
// Retrieve User Info ...
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await TermsProvider.HasTerms(
|
|
language: language
|
|
);
|
|
|
|
//
|
|
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>
|
|
[AllowAnonymous]
|
|
[HttpGet("Terms/{language}")]
|
|
public async Task<ActionResult<string>> GetTerms(
|
|
[FromRoute] string language = null
|
|
)
|
|
{
|
|
//
|
|
// Do ...
|
|
try
|
|
{
|
|
//
|
|
// Retrieve User Info ...
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await TermsProvider.GetTerms(
|
|
language: language
|
|
);
|
|
|
|
//
|
|
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}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public async Task<ActionResult<string>> AddTerms(
|
|
[FromRoute] string language,
|
|
[FromQuery] string terms
|
|
)
|
|
{
|
|
//
|
|
// Do ...
|
|
try
|
|
{
|
|
//
|
|
// Retrieve User Info ...
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await TermsProvider.AddTerms(
|
|
terms: terms,
|
|
language: language,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId
|
|
);
|
|
|
|
//
|
|
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}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public async Task<ActionResult<bool>> RemoveTerms(
|
|
[FromRoute] string language
|
|
)
|
|
{
|
|
//
|
|
// Do ...
|
|
try
|
|
{
|
|
//
|
|
// Retrieve User Info ...
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await TermsProvider.RemoveTerms(
|
|
language: language,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId
|
|
);
|
|
|
|
//
|
|
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}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public async Task<ActionResult<bool>> UpdateTerms(
|
|
[FromRoute] string language,
|
|
[FromQuery] string terms
|
|
)
|
|
{
|
|
//
|
|
// Do ...
|
|
try
|
|
{
|
|
//
|
|
// Retrieve User Info ...
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await TermsProvider.UpdateTerms(
|
|
terms: terms,
|
|
language: language,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |