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
{
///
/// Implementing Terms and Conditions Action Provider ...
///
public partial class ConfigurationsController : IXTermsConditionsControllerActions
{
//
#region Actions ...
///
/// Retrieved all Exists Languages Terms and Conditions ...
///
///
[HttpGet("Terms/Languages")]
[Authorize(Policy = XPolicies.EnabledUser)]
public async Task>> 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;
}
}
///
/// Check Has Terms and Conditions based on Specified Language ...
///
/// if null, used Default Language ...
///
[HttpGet("Terms/{language}/Has")]
[Authorize(Policy = XPolicies.EnabledUser)]
public async Task> 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;
}
}
///
/// Retrieve Terms and Conditions for Specified Language ...
///
/// if null, used Default Language ...
///
[AllowAnonymous]
[HttpGet("Terms/{language}")]
public async Task> 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;
}
}
///
/// Add Terms and Conditions for Specified Language ...
///
///
///
///
[HttpPost("Terms/{language}")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task> 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;
}
}
///
/// Remove Terms and Conditions of Specified Language ...
///
///
///
[HttpDelete("Terms/{language}")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task> 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;
}
}
///
/// Update Terms and Conditions of Specified Language ...
///
///
///
///
[HttpPut("Terms/{language}")]
[Authorize(Policy = XPolicies.EnabledAdmin)]
public async Task> 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
}
}