326 lines
9.3 KiB
C#
326 lines
9.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
using xAiApi.Base;
|
|
using xAiApi.Data.Interfaces;
|
|
using xAiApi.Data.Models.Entities;
|
|
using xCommons.Configurations;
|
|
using xCommons.Extensions;
|
|
using xCommons.Providers;
|
|
using xIdentityHelper;
|
|
using xIdentityService.Interfaces;
|
|
using xModels.Base;
|
|
using xModels.Dtos;
|
|
using xPushService.Base;
|
|
using xPushService.Constants;
|
|
|
|
namespace xAiApi.Controllers.V1.Entities
|
|
{
|
|
/// <summary>
|
|
/// Simple XTest Entity Controller ...
|
|
/// </summary>
|
|
public class TestsController : XIBaseV1EntityHubController<XTest, int>
|
|
{
|
|
//
|
|
#region Constructor ...
|
|
public TestsController(
|
|
ILogger<TestsController> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXTestRepository repository,
|
|
IHubContext<XBaseEntityHub<XTest, int>> hub = null
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider,
|
|
repository,
|
|
hub
|
|
)
|
|
{ }
|
|
#endregion
|
|
|
|
//
|
|
#region Interface Implementations ...
|
|
//
|
|
#region Retrieve ...
|
|
[HttpGet("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<XTest>> Get(
|
|
[FromRoute] int id, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.Get(
|
|
id: id,
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<IEnumerable<XTest>>> GetAll(
|
|
[FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.GetAll(
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet("FindOne/{query}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<XTest>> FindOne(
|
|
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.FindOne(
|
|
query: query,
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet("FindMany/{query}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<IEnumerable<XTest>>> FindMany(
|
|
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.FindMany(
|
|
query: query,
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet("Query")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<XQueryResult<XTest>>> Query(
|
|
[FromQuery] XQuery query, [FromQuery] bool ignoreSoftDeleteds = true
|
|
)
|
|
{
|
|
return await base
|
|
.Query(
|
|
query: query,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Add ...
|
|
[HttpPost]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XTest>> Add(
|
|
[FromBody] XTest item
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.Add(item);
|
|
|
|
//
|
|
// Handle Sending Push Notification ...
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.Add.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("AddOrUpdate")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XTest>> AddOrUpdate(
|
|
[FromBody] XTest item
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.AddOrUpdate(item);
|
|
|
|
//
|
|
// Handle Sending Push Notification ...
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("AddMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult> AddMany(
|
|
[FromBody] XBaseRangeRequest<XTest> request
|
|
)
|
|
{
|
|
//
|
|
var result = await base
|
|
.AddMany(request);
|
|
|
|
//
|
|
if (!(result as OkObjectResult).IsNull())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.AddMany.GetStringValue(),
|
|
payLoad: request.Items.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Update ...
|
|
[HttpPut("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XTest>> Update(
|
|
[FromRoute] int id, [FromBody] XTest item
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.Update(
|
|
id,
|
|
item
|
|
);
|
|
|
|
//
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.Update.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("UpdateMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<bool>> UpdateMany(
|
|
[FromBody] XBaseRangeRequest<XTest> request
|
|
)
|
|
{
|
|
//
|
|
var result = await base
|
|
.UpdateMany(request);
|
|
|
|
//
|
|
var resultObject = (result.Result as OkObjectResult).Value;
|
|
if (!resultObject.IsNull() && (bool)resultObject)
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
|
payLoad: request.Items.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Exists ...
|
|
[HttpGet("{id}/IsExists")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<bool>> IsExists(
|
|
[FromRoute] int id, [FromQuery] bool ignoreSoftDeleteds = true
|
|
)
|
|
{
|
|
return await base
|
|
.IsExists(
|
|
id: id,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Remove ...
|
|
[HttpDelete("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XTest>> Remove(
|
|
[FromRoute] int id, bool softDelete = true
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.Remove(
|
|
id: id,
|
|
softDelete: softDelete
|
|
);
|
|
|
|
//
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("RemoveMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult> RemoveMany(
|
|
[FromBody] XBaseRangeRequest<XTest> request, bool softDelete = true
|
|
)
|
|
{
|
|
//
|
|
var result = await base
|
|
.RemoveMany(
|
|
request: request,
|
|
softDelete: softDelete
|
|
);
|
|
|
|
//
|
|
if (!(result as OkObjectResult).IsNull())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
|
payLoad: request.Items.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
} |