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 xApi.Base; 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; using xStringService.Interfaces.Entities; using xStringService.Models.Entities; namespace xApi.Controllers.V1.Entities { /// /// Simple XString Entity Controller ... /// public class StringsController : XIBaseV1EntityHubController { // #region Constructor ... public StringsController( ILogger logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXStringRepository repository, IHubContext> 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> 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>> 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> 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>> 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>> 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> Add( [FromBody] XString 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> AddOrUpdate( [FromBody] XString 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 AddMany( [FromBody] XBaseRangeRequest 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> Update( [FromRoute] int id, [FromBody] XString 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> UpdateMany( [FromBody] XBaseRangeRequest 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> 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> 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 RemoveMany( [FromBody] XBaseRangeRequest 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 } }