last ...
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xDataService.Controllers;
|
||||
using xDataService.Interfaces;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Controllers
|
||||
{
|
||||
public abstract class XTagRepositoryControllerBase : XBaseRepositoryController<XTag, int>, IXBaseRepositoryController<XTag, int>
|
||||
{
|
||||
protected XTagRepositoryControllerBase(
|
||||
ILogger<XTagRepositoryControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
XValidationProvider validationProvider,
|
||||
IXTagRepository repository,
|
||||
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
|
||||
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
validationProvider,
|
||||
repository,
|
||||
defaultOrderBuilder,
|
||||
defaultIncludeBuilder
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Controllers;
|
||||
using xPushService.Interfaces;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
using xTagService.Providers.Entities;
|
||||
|
||||
namespace xTagService.Controllers
|
||||
{
|
||||
public abstract class XTagRepositoryProviderControllerBase : XBaseRepositoryProviderController<XTag, int, XTagEntityHub>, IXBaseRepositoryProviderController<XTag, int, XTagEntityHub>
|
||||
{
|
||||
protected XTagRepositoryProviderControllerBase(
|
||||
ILogger<XTagRepositoryProviderControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXTagRepositoryProvider provider,
|
||||
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
|
||||
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
provider,
|
||||
defaultOrderBuilder,
|
||||
defaultIncludeBuilder
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -1,448 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Dtos;
|
||||
using xTagService.Interfaces;
|
||||
using xDataService.Controllers;
|
||||
using xDataService.Interfaces;
|
||||
using xTagService.Interfaces.Dtos;
|
||||
using xTagService.Models.Dtos;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// a Controller base Class which implement based Actions to Provides Tag Provider Access ...
|
||||
/// </summary>
|
||||
public abstract class XTagServiceControllerBase : XIBaseProviderController, IXTagServiceControllerActions
|
||||
public abstract class XTagServiceControllerBase : XBaseServiceController<XTag, XTagDto, int>, IXBaseServiceController<XTag, XTagDto, int>
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
public IXTagProvider TagProvider { get; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XTagServiceControllerBase(
|
||||
ILogger logger,
|
||||
IXTagProvider tagProvider,
|
||||
protected XTagServiceControllerBase(
|
||||
ILogger<XTagServiceControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
XValidationProvider validationProvider,
|
||||
IXTagRepositoryService repositoryService,
|
||||
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
|
||||
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
validationProvider,
|
||||
repositoryService,
|
||||
defaultOrderBuilder,
|
||||
defaultIncludeBuilder
|
||||
)
|
||||
{
|
||||
//
|
||||
TagProvider = tagProvider;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Add Tag by Providing Dto ...
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("")]
|
||||
public virtual async Task<ActionResult<XTagDto>> Add(
|
||||
[FromBody] XTagDto model
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Retrieve User Info ...
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
|
||||
var userId = userInfo.UserId;
|
||||
|
||||
//
|
||||
var result = await TagProvider.Add(
|
||||
model: model,
|
||||
connectionId: connectionId
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Specified Tag ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
public virtual async Task<ActionResult<XTagDto>> Update(
|
||||
[FromRoute] int id,
|
||||
[FromBody] XTagDto model
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Retrieve User Info ...
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
|
||||
var userId = userInfo.UserId;
|
||||
|
||||
//
|
||||
var result = await TagProvider.Update(
|
||||
id: id,
|
||||
model: model,
|
||||
connectionId: connectionId
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Tag by ID ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
public virtual async Task<ActionResult<XTagDto>> Remove(
|
||||
[FromRoute] int id
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Retrieve User Info ...
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
|
||||
var userId = userInfo.UserId;
|
||||
|
||||
//
|
||||
var result = await TagProvider.Remove(
|
||||
id: id,
|
||||
connectionId: connectionId
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Tag Dto by ID ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public virtual async Task<ActionResult<XTagDto>> Get(
|
||||
[FromRoute] int id
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider.Get(
|
||||
id: id
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Tag Dto by it's Label ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetTag")]
|
||||
public virtual async Task<ActionResult<XTagDto>> GetTag(
|
||||
[FromQuery] string tag
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider.GetTag(
|
||||
tag: tag
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve All Exists Tags ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("All")]
|
||||
public virtual async Task<ActionResult<IEnumerable<XTagDto>>> GetAll()
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider.GetAll();
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search For Specified Tag by Providing a query on Label ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindOne")]
|
||||
public virtual async Task<ActionResult<XTagDto>> FindOne(
|
||||
[FromQuery] string query
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
Expression<Func<XTag, bool>> whereClause = t =>
|
||||
!query.IsNullOrEmpty() &&
|
||||
t.Tag.ToNormalString()
|
||||
.Contains(query.ToNormalString());
|
||||
var result = await TagProvider.FindOne(
|
||||
whereClause: whereClause
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search For Specified Tags By Providing Query on Labels ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindMany")]
|
||||
public virtual async Task<ActionResult<IEnumerable<XTagDto>>> FindMany(
|
||||
[FromQuery] string query
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
Expression<Func<XTag, bool>> whereClause = t =>
|
||||
!query.IsNullOrEmpty() &&
|
||||
t.Tag.ToNormalString()
|
||||
.Contains(query.ToNormalString());
|
||||
var result = await TagProvider.FindMany(
|
||||
whereClause: whereClause
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Tags based on Query Model ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Query")]
|
||||
public virtual async Task<ActionResult<XQueryResult<XTagDto>>> Query(
|
||||
[FromQuery] XQuery query
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider
|
||||
.Query(query);
|
||||
|
||||
//
|
||||
return Ok(result.
|
||||
ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count Exists Tags ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Count")]
|
||||
public virtual async Task<ActionResult<int>> Count()
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider
|
||||
.Count();
|
||||
|
||||
//
|
||||
return Ok(result.
|
||||
ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Tag Exists by ID ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/IsExists")]
|
||||
public virtual async Task<ActionResult<bool>> IsExists(
|
||||
[FromRoute] int id
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider
|
||||
.IsExists(id);
|
||||
|
||||
//
|
||||
return Ok(result.
|
||||
ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Tag Exists by Providing Label ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("IsTagExists")]
|
||||
public virtual async Task<ActionResult<bool>> IsTagExists(
|
||||
[FromQuery] string tag
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await TagProvider
|
||||
.IsTagExists(tag);
|
||||
|
||||
//
|
||||
return Ok(result.
|
||||
ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Controllers;
|
||||
using xPushService.Interfaces;
|
||||
using xTagService.Interfaces.Dtos;
|
||||
using xTagService.Models.Dtos;
|
||||
using xTagService.Models.Entities;
|
||||
using xTagService.Providers.Dtos;
|
||||
|
||||
namespace xTagService.Controllers
|
||||
{
|
||||
public abstract class XTagServiceProviderControllerBase : XBaseServiceProviderController<XTag, XTagDto, int, XTagDtoHub>, IXBaseServiceProviderController<XTag, XTagDto, int, XTagDtoHub>
|
||||
{
|
||||
protected XTagServiceProviderControllerBase(
|
||||
ILogger<XTagServiceProviderControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXTagServiceProvider provider,
|
||||
Func<IQueryable<XTag>, IOrderedQueryable<XTag>> defaultOrderBuilder = null,
|
||||
Func<IQueryable<XTag>, IIncludableQueryable<XTag, object>> defaultIncludeBuilder = null
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
provider,
|
||||
defaultOrderBuilder,
|
||||
defaultIncludeBuilder
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user