using System; using System.Linq; using System.Threading; using xCommons.Providers; using xCommons.Extensions; using xExceptions.Constants; using System.Threading.Tasks; using xCommons.Configurations; using xTagService.Controllers; using Microsoft.AspNetCore.Mvc; using xContentService.Interfaces; using xContentService.Models.Dtos; using xIdentityService.Interfaces; using Microsoft.Extensions.Logging; using xContentService.Providers.Dtos; using xContentService.Models.Entities; using Microsoft.EntityFrameworkCore.Query; using xContentService.Interfaces.Controllers; namespace xContentService.Controllers { public abstract class XContentProviderControllerBase : XBaseProvidedHasTagControllerBase, IXContentProviderController { private readonly IXContentProvider provider; protected XContentProviderControllerBase( ILogger> logger, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider, IXContentProvider provider, IXContentTagProvided tagProvided, Func, IOrderedQueryable> defaultOrderBuilder = null, Func, IIncludableQueryable> defaultIncludeBuilder = null ) : base( logger, appConfiguration, identityProvider, validationProvider, provider, tagProvided, defaultOrderBuilder, defaultIncludeBuilder ) { this.provider = provider; } /// /// Add an item ... /// /// /// /// /// [HttpPost("Add")] public async Task> Add( [FromBody] XContentDto item, [FromQuery] string language = null, CancellationToken cancellationToken = default ) { // try { // // Validate ... if (!ModelState.IsValid) { XException.InvalidArgs.Throw(); } await ValidationProvider .GroupValidationBuilder() .AddNotNull(item) .AddNotEmpty(item.Title) .ValidateGroupAsync(); // var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); // // Normalize Language ... if (language.IsNullOrEmpty()) { language = AppConfiguration.DefaultLanguage; } if (language.IsNullOrEmpty()) { XException.InvalidData.Throw(); } // var result = await provider.Add( item: item, userInfo: userInfo, language: language, connectionId: connectionId, cancellationToken: cancellationToken ); // return result; } catch (Exception ex) { // var result = GetExceptionActionResult(ex); return result; } } } }