last ...
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xPushService.Base;
|
||||
using xTagService.Interfaces.Dtos;
|
||||
using xTagService.Models.Dtos;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Dtos
|
||||
{
|
||||
public class XTagDtoHub : XBaseDtoHub<XTag, XTagDto, int>, IXTagDtoHub
|
||||
{
|
||||
public XTagDtoHub(
|
||||
ILogger<XTagDtoHub> logger
|
||||
) : base(logger)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces.Dtos;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Dtos;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Dtos
|
||||
{
|
||||
public class XTagRepositoryService : XBaseRepositoryService<XTag, XTagDto, int>, IXTagRepositoryService
|
||||
{
|
||||
public XTagRepositoryService(
|
||||
IXTagRepository repository,
|
||||
IEnumerable<Profile> mapperProfiles = null
|
||||
) : base(
|
||||
repository,
|
||||
mapperProfiles
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using xDataService.Configuration;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Base;
|
||||
using xTagService.Interfaces.Dtos;
|
||||
using xTagService.Models.Dtos;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Dtos
|
||||
{
|
||||
public class XTagServiceProvider : XBaseDtoProvider<XTag, XTagDto, int, XTagDtoHub>, IXTagServiceProvider
|
||||
{
|
||||
public XTagServiceProvider(
|
||||
IHubContext<XTagDtoHub> hub,
|
||||
XDataServiceConfiguration dataConfiguration,
|
||||
IXTagRepositoryService service,
|
||||
IXIdentityProvider identityProvider = null
|
||||
) : base(
|
||||
hub,
|
||||
dataConfiguration,
|
||||
service,
|
||||
identityProvider
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Db;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagEFRepository<TContext> : XBaseEFRepository<XTag, int, TContext>, IXTagRepository
|
||||
where TContext : XDbContext
|
||||
{
|
||||
public XTagEFRepository(
|
||||
IXUnitOfWorks<TContext> unitOfWorks,
|
||||
XDataServiceConfiguration configuration,
|
||||
IXTagKeyGenerator keyGenerator = null,
|
||||
IXTagRepositoryEvents baseRepositoryEvents = null
|
||||
) : base(
|
||||
unitOfWorks,
|
||||
configuration,
|
||||
keyGenerator,
|
||||
baseRepositoryEvents
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xPushService.Base;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagEntityHub : XBaseEntityHub<XTag, int>, IXTagEntityHub
|
||||
{
|
||||
public XTagEntityHub(
|
||||
ILogger<XTagEntityHub> logger
|
||||
) : base(logger)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagInMemoryRepository : XBaseInMemoryRepository<XTag, int>, IXTagRepository
|
||||
{
|
||||
public XTagInMemoryRepository(
|
||||
XDataServiceConfiguration configuration,
|
||||
IXTagKeyGenerator keyGenerator = null,
|
||||
IXTagRepositoryEvents baseRepositoryEvents = null
|
||||
) : base(
|
||||
configuration,
|
||||
keyGenerator,
|
||||
baseRepositoryEvents
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagKeyGenerator : XIntKeyGenerator<XTag>, IXTagKeyGenerator
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagMongoRepository : XBaseMongoRepository<XTag, int>, IXTagRepository
|
||||
{
|
||||
public XTagMongoRepository(
|
||||
XDataBaseConfiguration dbConfiguration,
|
||||
XDataServiceConfiguration configuration,
|
||||
string collectionName = null,
|
||||
IXTagKeyGenerator keyGenerator = null,
|
||||
IXTagRepositoryEvents baseRepositoryEvents = null
|
||||
) : base(
|
||||
dbConfiguration,
|
||||
configuration,
|
||||
collectionName,
|
||||
keyGenerator,
|
||||
baseRepositoryEvents
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagRepositoryEvents : XBaseRepositoryEvents<XTag>, IXTagRepositoryEvents
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using xDataService.Configuration;
|
||||
using xIdentityService.Interfaces;
|
||||
using xPushService.Base;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public class XTagRepositoryProvider : XBaseEntityProvider<XTag, int, XTagEntityHub>, IXTagRepositoryProvider
|
||||
{
|
||||
public XTagRepositoryProvider(
|
||||
IHubContext<XTagEntityHub> hub,
|
||||
IXTagRepository repository,
|
||||
XDataServiceConfiguration dataConfiguration,
|
||||
IXIdentityProvider identityProvider = null
|
||||
) : base(
|
||||
hub,
|
||||
repository,
|
||||
dataConfiguration,
|
||||
identityProvider
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Providers;
|
||||
using xTagService.Interfaces;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.Entities
|
||||
{
|
||||
public abstract class XTagSeederBase : XBaseDbSeeder<XTag, int>, IXTagSeeder
|
||||
{
|
||||
protected XTagSeederBase(
|
||||
string entity,
|
||||
string database,
|
||||
IXBaseRepository<XTag, int> repository,
|
||||
XDataServiceConfiguration dataServiceConfiguration
|
||||
) : base(
|
||||
entity,
|
||||
database,
|
||||
repository,
|
||||
dataServiceConfiguration
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.GraphQL
|
||||
{
|
||||
public class XTagGraphQLTypeHelper : XBaseGraphQLTypeHelper<XTag, int>, IXTagGraphQLTypeHelper
|
||||
{
|
||||
public XTagGraphQLTypeHelper(
|
||||
XDataServiceConfiguration configuration
|
||||
) : base(configuration)
|
||||
{ }
|
||||
|
||||
public override string GetInQueryCollectionName()
|
||||
{
|
||||
return "tags";
|
||||
}
|
||||
|
||||
public override string GetInQuerySingleName()
|
||||
{
|
||||
return "tag";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using GraphQL.Types;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.GraphQL;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.GraphQL
|
||||
{
|
||||
public class XTagGraphQuery : XBaseGraphQLQuery<XTag, int, XTagGraphType, IntGraphType>
|
||||
{
|
||||
public XTagGraphQuery(
|
||||
XDataServiceConfiguration configuration,
|
||||
IXTagRepository repository,
|
||||
IXTagGraphQLTypeHelper helper
|
||||
) : base(
|
||||
configuration,
|
||||
repository,
|
||||
helper
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using GraphQL.Types;
|
||||
|
||||
namespace xTagService.Providers.GraphQL
|
||||
{
|
||||
public class XTagGraphSchema : Schema
|
||||
{
|
||||
public XTagGraphSchema(IServiceProvider services) : base(services)
|
||||
{
|
||||
Query = (XTagGraphQuery)services.GetService(typeof(XTagGraphQuery));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using xDataService.GraphQL;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers.GraphQL
|
||||
{
|
||||
public class XTagGraphType : XBaseGraphObjectType<XTag, int>
|
||||
{
|
||||
public XTagGraphType() : base()
|
||||
{
|
||||
Field(x => x.Tag);
|
||||
Field(x => x.References);
|
||||
}
|
||||
}
|
||||
}
|
||||
+251
-190
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Extensions;
|
||||
using xDataService.Models;
|
||||
@@ -10,6 +9,7 @@ using xExceptions.Constants;
|
||||
using xModels.Dtos;
|
||||
using xTagService.Extensions;
|
||||
using xTagService.Interfaces;
|
||||
using xTagService.Interfaces.Dtos;
|
||||
using xTagService.Models.Dtos;
|
||||
|
||||
namespace xTagService.Providers
|
||||
@@ -26,14 +26,14 @@ namespace xTagService.Providers
|
||||
/// <summary>
|
||||
/// Tag Provider for Maipulating Tags ...
|
||||
/// </summary>
|
||||
public IXTagProvider TagProvider { get; }
|
||||
public IXTagServiceProvider TagProvider { get; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XBaseTagProvider(
|
||||
string providedFor,
|
||||
IXTagProvider tagProvider
|
||||
IXTagServiceProvider tagProvider
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -49,10 +49,12 @@ namespace xTagService.Providers
|
||||
/// </summary>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> GetReference(
|
||||
TKey providedForId,
|
||||
int forIndex = 0
|
||||
int forIndex = 0,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -71,7 +73,11 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Retrieve Last Index ...
|
||||
var maxIndex = (await GetReferencingIndexes(providedForId)).Max();
|
||||
var maxIndex = (await GetReferencingIndexes(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
))
|
||||
.Max();
|
||||
if (forIndex > maxIndex)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
@@ -82,17 +88,18 @@ namespace xTagService.Providers
|
||||
forIndex: forIndex,
|
||||
providedForId: providedForId
|
||||
);
|
||||
var entity = TagProvider.Repository
|
||||
.AsQueryable()
|
||||
.Where(t => t.References.Contains(indexedIdentifier))
|
||||
.FirstOrDefault();
|
||||
if (entity.IsNullOrDefault())
|
||||
var result = await TagProvider.FindOneAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.References.Contains(indexedIdentifier)
|
||||
);
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await Task.FromResult(entity.ToDto());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -100,8 +107,12 @@ namespace xTagService.Providers
|
||||
/// Retrieve all Exists References of Specific Provided ID ...
|
||||
/// </summary>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XTagDto>> GetAllReferences(TKey providedForId)
|
||||
public async Task<IEnumerable<XTagDto>> GetAllReferences(
|
||||
TKey providedForId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
@@ -112,34 +123,28 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
var identifier = GetProvidedID(providedForId);
|
||||
var entities = TagProvider.Repository
|
||||
.AsQueryable()
|
||||
.Where(t => t.References.Contains(identifier))
|
||||
.AsEnumerable();
|
||||
var result = await TagProvider.FindManyAsync(
|
||||
orderBuilder: null,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.References.Contains(identifier)
|
||||
);
|
||||
|
||||
//
|
||||
var result = new List<XTagDto>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
//
|
||||
var dto = entity.ToDto();
|
||||
if (!dto.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
result.Add(dto);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return await Task.FromResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract all Referencing Models for Specified Key ...
|
||||
/// </summary>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XReference<TKey>>> GetAllReferencings(TKey providedForId)
|
||||
public async Task<IEnumerable<XReference<TKey>>> GetAllReferencings(
|
||||
TKey providedForId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
@@ -154,27 +159,34 @@ namespace xTagService.Providers
|
||||
var identifier = GetProvidedID(providedForId);
|
||||
|
||||
//
|
||||
var result = TagProvider.Repository
|
||||
.AsQueryable()
|
||||
.Where(te => te.References.Contains(identifier))
|
||||
.Select(te => te.References)
|
||||
.ToList()
|
||||
.SelectMany(tr => tr.ParseXReferenceList<TKey>())
|
||||
.Where(tr => tr.ProvidedFor == Provider && $"{tr.ReferencedTo}" == $"{providedForId}")
|
||||
.OrderBy(tr => tr.Index)
|
||||
.AsEnumerable()
|
||||
;
|
||||
var result = (await TagProvider.FindManyAsync(
|
||||
orderBuilder: null,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.References.Contains(identifier)
|
||||
))
|
||||
.Select(x => x.References)
|
||||
.ToList()
|
||||
.SelectMany(x => x.ParseXReferenceList<TKey>())
|
||||
.Where(x => x.ProvidedFor == Provider && $"{x.ReferencedTo}" == $"{providedForId}")
|
||||
.OrderBy(x => x.Index)
|
||||
.AsEnumerable();
|
||||
|
||||
//
|
||||
return await Task.FromResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count References ...
|
||||
/// </summary>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> CountReferences(TKey providedForId)
|
||||
public async Task<int> CountReferences(
|
||||
TKey providedForId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
@@ -186,23 +198,29 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
var identifier = GetProvidedID(providedForId);
|
||||
var result = TagProvider.Repository
|
||||
.AsQueryable()
|
||||
.Where(t => t.References.Contains(identifier))
|
||||
.Count();
|
||||
var result = (await TagProvider.FindManyAsync(
|
||||
orderBuilder: null,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x => x.References.Contains(identifier)
|
||||
))
|
||||
.Count();
|
||||
|
||||
//
|
||||
return await Task.FromResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve References of Specific Provided ID as Query ...
|
||||
/// </summary>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XTagDto>> QueryReferences(
|
||||
XQuery query,
|
||||
TKey providedForId
|
||||
TKey providedForId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -213,64 +231,15 @@ namespace xTagService.Providers
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
query = query.NormalizeQuery(TagProvider.DataConfiguration);
|
||||
|
||||
//
|
||||
var items = await GetAllReferences(providedForId);
|
||||
var totalItemsCount = items.Count();
|
||||
|
||||
//
|
||||
// Apply Filter ...
|
||||
if (!query.Filter.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
items = items
|
||||
.ApplyFilter(query.Filter);
|
||||
}
|
||||
int filteredItemsCount = items.Count();
|
||||
|
||||
//
|
||||
// Count Pages ...
|
||||
var totalPagesCount = query.CountPages(totalItemsCount);
|
||||
var filteredPagesCount = query.CountPages(filteredItemsCount);
|
||||
|
||||
//
|
||||
// Apply Paging and Sorting ...
|
||||
if (totalItemsCount > 0 &&
|
||||
filteredItemsCount > 0)
|
||||
{
|
||||
//
|
||||
// Apply Sorting ...
|
||||
items = items
|
||||
.ToList()
|
||||
.ApplySorting(
|
||||
query.SortBy,
|
||||
query.IsAscending
|
||||
);
|
||||
|
||||
//
|
||||
// Apply Paging ...
|
||||
items = items
|
||||
.ToList()
|
||||
.ApplyPaging(
|
||||
query.Page,
|
||||
query.PageSize
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
var result = new XQueryResult<XTagDto>
|
||||
{
|
||||
Page = query.Page,
|
||||
Items = items.ToList(),
|
||||
PageSize = query.PageSize,
|
||||
TotalPages = totalPagesCount,
|
||||
TotalItems = totalItemsCount,
|
||||
TotalFilteredPages = filteredPagesCount,
|
||||
TotalFilteredItems = filteredItemsCount
|
||||
};
|
||||
var identifier = GetProvidedID(providedForId);
|
||||
var result = await TagProvider.QueryAsync(
|
||||
query: query,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder: x => x.OrderBy(y => y.Id),
|
||||
predicate: x => x.References.Contains(identifier)
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -281,13 +250,14 @@ namespace xTagService.Providers
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddReference(
|
||||
XTagDto model,
|
||||
TKey providedForId,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -306,7 +276,7 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Check Model Exists ...
|
||||
result = await TagProvider.IsExists(model.Id);
|
||||
result = await TagProvider.IsExistsAsync(model.Id);
|
||||
if (!result)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
@@ -314,17 +284,29 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Update Model by Retrieving ...
|
||||
model = await TagProvider.Get(model.Id);
|
||||
model = await TagProvider.GetAsync(
|
||||
id: model.Id,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve all References ...
|
||||
var references = await GetAllReferences(providedForId);
|
||||
var references = await GetAllReferences(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Check isReferenced or not ...
|
||||
result = references.Any(r => r.Id == model.Id &&
|
||||
r.References.Any(rf => rf.ProvidedFor == Provider &&
|
||||
rf.ReferencedTo == $"{providedForId}"));
|
||||
result = references
|
||||
.Any(r =>
|
||||
r.Id == model.Id &&
|
||||
r.GetReferences()
|
||||
.Any(rf =>
|
||||
rf.ProvidedFor == Provider &&
|
||||
rf.ReferencedTo == $"{providedForId}"));
|
||||
if (result)
|
||||
{
|
||||
return result;
|
||||
@@ -332,21 +314,30 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Here means there is not any reference to ProvidedForId ...
|
||||
int forIndex = await CountReferences(providedForId);
|
||||
model.References.Add(new XReference<string>
|
||||
int forIndex = await CountReferences(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var modelReferences = model.GetReferences();
|
||||
modelReferences.Add(new XReference<string>
|
||||
{
|
||||
Index = forIndex,
|
||||
ProvidedFor = Provider,
|
||||
ReferencedTo = $"{providedForId}"
|
||||
});
|
||||
modelReferences = modelReferences
|
||||
.OrderBy(r => r.Index)
|
||||
.ToList();
|
||||
model = model.UpdateReferences(modelReferences);
|
||||
|
||||
//
|
||||
// Update Data Base ...
|
||||
model = await TagProvider
|
||||
.Update(
|
||||
id: model.Id,
|
||||
model: model,
|
||||
connectionId: connectionId
|
||||
model = await TagProvider.UpdateAsync(
|
||||
id: model.Id,
|
||||
item: model,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = !model.IsNullOrDefault();
|
||||
|
||||
@@ -360,11 +351,13 @@ namespace xTagService.Providers
|
||||
/// <param name="model"></param>
|
||||
/// <param name="reference"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddReference(
|
||||
XTagDto model,
|
||||
XReference<TKey> reference,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -384,6 +377,7 @@ namespace xTagService.Providers
|
||||
result = await AddReference(
|
||||
model: model,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
providedForId: reference.ReferencedTo
|
||||
);
|
||||
|
||||
@@ -397,12 +391,13 @@ namespace xTagService.Providers
|
||||
/// <param name="model"></param>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="forIndex">if null, removes all</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemoveReference(
|
||||
XTagDto model,
|
||||
TKey providedForId,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -418,7 +413,12 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Retrieve Model ...
|
||||
model = await TagProvider.Get(model.Id);
|
||||
model = await TagProvider.GetAsync(
|
||||
id: model.Id,
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = !model.IsNullOrDefault();
|
||||
if (!result)
|
||||
{
|
||||
@@ -427,11 +427,17 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Reading Referencing Indexes ...
|
||||
var indexes = await GetReferencingIndexes(providedForId);
|
||||
var indexes = await GetReferencingIndexes(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Check Model Reference to ID ...
|
||||
var referencesCount = await CountReferences(providedForId);
|
||||
var referencesCount = await CountReferences(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = referencesCount == 0;
|
||||
if (result)
|
||||
{
|
||||
@@ -442,9 +448,11 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Check Model is Trully Referenced to ProvidedForId or not ...
|
||||
var reference = model.References
|
||||
.FirstOrDefault(r => r.ProvidedFor == Provider &&
|
||||
r.ReferencedTo == $"{providedForId}");
|
||||
var reference = model
|
||||
.GetReferences()
|
||||
.FirstOrDefault(r =>
|
||||
r.ProvidedFor == Provider &&
|
||||
r.ReferencedTo == $"{providedForId}");
|
||||
result = !reference.IsNullOrDefault();
|
||||
if (!result)
|
||||
{
|
||||
@@ -453,17 +461,22 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Remove Referenced Item from Model ...
|
||||
model.References = model.References
|
||||
.Where(r => !(r.ProvidedFor == Provider &&
|
||||
r.ReferencedTo == $"{providedForId}"))
|
||||
var modelReferences = model
|
||||
.GetReferences()
|
||||
.Where(r =>
|
||||
!(r.ProvidedFor == Provider &&
|
||||
r.ReferencedTo == $"{providedForId}"))
|
||||
.ToList();
|
||||
model = model.UpdateReferences(modelReferences);
|
||||
|
||||
//
|
||||
// Update DataBase ...
|
||||
model = await TagProvider.Update(
|
||||
model = await TagProvider.UpdateAsync(
|
||||
item: model,
|
||||
id: model.Id,
|
||||
model: model,
|
||||
connectionId: connectionId
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
@@ -488,12 +501,14 @@ namespace xTagService.Providers
|
||||
//
|
||||
var dto = await GetReference(
|
||||
forIndex: i,
|
||||
providedForId: providedForId
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!dto.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
dto.References
|
||||
var dtoReferences = dto.GetReferences();
|
||||
dtoReferences
|
||||
.ToList()
|
||||
.ForEach(iref =>
|
||||
{
|
||||
@@ -507,12 +522,15 @@ namespace xTagService.Providers
|
||||
iref.Index = i - 1;
|
||||
}
|
||||
});
|
||||
dto = dto.UpdateReferences(dtoReferences);
|
||||
|
||||
//
|
||||
dto = await TagProvider.Update(
|
||||
dto = await TagProvider.UpdateAsync(
|
||||
item: dto,
|
||||
id: dto.Id,
|
||||
model: dto,
|
||||
connectionId: connectionId
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -526,13 +544,15 @@ namespace xTagService.Providers
|
||||
/// Remove Reference a Model for Specific XRefence<TKey> ...
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="reference"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemoveReference(
|
||||
XTagDto model,
|
||||
XReference<TKey> reference,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -548,6 +568,7 @@ namespace xTagService.Providers
|
||||
var result = await RemoveReference(
|
||||
model: model,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
providedForId: reference.ReferencedTo
|
||||
);
|
||||
|
||||
@@ -560,10 +581,12 @@ namespace xTagService.Providers
|
||||
/// </summary>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemoveReferences(
|
||||
TKey providedForId,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -575,7 +598,10 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
var result = false;
|
||||
var references = await GetAllReferences(providedForId);
|
||||
var references = await GetAllReferences(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!references.IsNull() && references.HasChild())
|
||||
{
|
||||
//
|
||||
@@ -583,16 +609,19 @@ namespace xTagService.Providers
|
||||
{
|
||||
//
|
||||
// Remove Reference ...
|
||||
reference.References = reference.References
|
||||
var itemReferences = reference.GetReferences()
|
||||
.Where(r =>
|
||||
r.ProvidedFor != Provider ||
|
||||
(r.ProvidedFor == Provider &&
|
||||
r.ReferencedTo != $"{providedForId}"))
|
||||
.ToList();
|
||||
var updatedModel = await TagProvider.Update(
|
||||
id: reference.Id,
|
||||
model: reference,
|
||||
connectionId: connectionId
|
||||
var updatedModel = reference.UpdateReferences(itemReferences);
|
||||
updatedModel = await TagProvider.UpdateAsync(
|
||||
saveChanges: true,
|
||||
item: updatedModel,
|
||||
id: updatedModel.Id,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!updatedModel.IsNullOrDefault())
|
||||
{
|
||||
@@ -613,13 +642,14 @@ namespace xTagService.Providers
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="forIndex"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddReference(
|
||||
string tag,
|
||||
TKey providedForId,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -635,7 +665,10 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Check Tag Exists ...
|
||||
result = IsExists(tag);
|
||||
result = await IsExists(
|
||||
tag: tag,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
@@ -644,9 +677,11 @@ namespace xTagService.Providers
|
||||
{
|
||||
Tag = tag,
|
||||
};
|
||||
tagDto = await TagProvider.Add(
|
||||
model: tagDto,
|
||||
connectionId: connectionId
|
||||
tagDto = await TagProvider.AddAsync(
|
||||
item: tagDto,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = !tagDto.IsNullOrDefault();
|
||||
if (!result)
|
||||
@@ -656,7 +691,10 @@ namespace xTagService.Providers
|
||||
}
|
||||
|
||||
//
|
||||
var dto = GetTagByTag(tag);
|
||||
var dto = await GetTagByTag(
|
||||
tag: tag,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = !dto.IsNullOrDefault();
|
||||
if (!result)
|
||||
{
|
||||
@@ -667,7 +705,8 @@ namespace xTagService.Providers
|
||||
result = await AddReference(
|
||||
model: dto,
|
||||
connectionId: connectionId,
|
||||
providedForId: providedForId
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
@@ -680,11 +719,13 @@ namespace xTagService.Providers
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="reference"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddReference(
|
||||
string tag,
|
||||
XReference<TKey> reference,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -706,6 +747,7 @@ namespace xTagService.Providers
|
||||
result = await AddReference(
|
||||
tag: tag,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
providedForId: reference.ReferencedTo
|
||||
);
|
||||
|
||||
@@ -718,21 +760,19 @@ namespace xTagService.Providers
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="forIndex">if null, removes all</param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemoveReference(
|
||||
string tag,
|
||||
TKey providedForId,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result =
|
||||
var result =
|
||||
!tag.IsNullOrEmpty() &&
|
||||
!providedForId.IsNull();
|
||||
if (!result)
|
||||
@@ -742,14 +782,20 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Check Tag Exists ...
|
||||
result = IsExists(tag);
|
||||
result = await IsExists(
|
||||
tag: tag,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var dto = GetTagByTag(tag);
|
||||
var dto = await GetTagByTag(
|
||||
tag: tag,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = !dto.IsNullOrDefault();
|
||||
if (!result)
|
||||
{
|
||||
@@ -760,7 +806,8 @@ namespace xTagService.Providers
|
||||
result = await RemoveReference(
|
||||
model: dto,
|
||||
connectionId: connectionId,
|
||||
providedForId: providedForId
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
@@ -771,21 +818,20 @@ namespace xTagService.Providers
|
||||
/// Remove Reference a Tag for Specific XRefence<TKey> ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="providedForId"></param>
|
||||
/// <param name="reference"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RemoveReference(
|
||||
string tag,
|
||||
XReference<TKey> reference,
|
||||
string connectionId = null
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result =
|
||||
var result =
|
||||
!tag.IsNullOrEmpty() &&
|
||||
!reference.IsNullOrDefault() &&
|
||||
!reference.ReferencedTo.IsNull() &&
|
||||
@@ -799,6 +845,7 @@ namespace xTagService.Providers
|
||||
result = await RemoveReference(
|
||||
tag: tag,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
providedForId: reference.ReferencedTo
|
||||
);
|
||||
|
||||
@@ -839,7 +886,10 @@ namespace xTagService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<int>> GetReferencingIndexes(TKey providedForId)
|
||||
private async Task<IEnumerable<int>> GetReferencingIndexes(
|
||||
TKey providedForId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
@@ -852,8 +902,12 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
var result = new List<int>();
|
||||
var referencings = await GetAllReferencings(providedForId);
|
||||
isValid = !referencings.IsNull() &&
|
||||
var referencings = await GetAllReferencings(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
isValid =
|
||||
!referencings.IsNull() &&
|
||||
referencings.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
@@ -871,7 +925,10 @@ namespace xTagService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
private XTagDto GetTagByTag(string tag)
|
||||
private async Task<XTagDto> GetTagByTag(
|
||||
string tag,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XTagDto result = null;
|
||||
@@ -880,20 +937,21 @@ namespace xTagService.Providers
|
||||
if (!tag.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
var entity = TagProvider.Repository
|
||||
.AsQueryable()
|
||||
.FirstOrDefault(e => e.Tag == tag);
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
result = entity.ToDto();
|
||||
}
|
||||
result = await TagProvider
|
||||
.FindOneAsync(
|
||||
predicate: x => x.Tag == tag,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool IsExists(string tag)
|
||||
private async Task<bool> IsExists(
|
||||
string tag,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = false;
|
||||
@@ -902,13 +960,16 @@ namespace xTagService.Providers
|
||||
if (!tag.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
var dto = GetTagByTag(tag);
|
||||
var dto = await GetTagByTag(
|
||||
tag: tag,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
result = !dto.IsNullOrDefault();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Providers;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers
|
||||
{
|
||||
public class XTagEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
|
||||
{
|
||||
public XTagEntityRegisterar()
|
||||
: base(nameof(XTagEntityRegisterar))
|
||||
{
|
||||
//
|
||||
// Add XTag Entity ...
|
||||
AddEntity<XTag, int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Entities ...
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder"></param>
|
||||
public override void ConfigureEntities(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.ConfigureEntities(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,571 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Configuration;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Dtos;
|
||||
using xPushService.Constants;
|
||||
using xTagService.Extensions;
|
||||
using xTagService.Hubs;
|
||||
using xTagService.Interfaces;
|
||||
using xTagService.Interfaces.Entities;
|
||||
using xTagService.Models.Dtos;
|
||||
using xTagService.Models.Entities;
|
||||
|
||||
namespace xTagService.Providers
|
||||
{
|
||||
public class XTagProvider : IXTagProvider
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
public IXTagRepository Repository { get; }
|
||||
public IHubContext<XTagEntityHub> Hub { get; }
|
||||
public IXIdentityProvider IdentityProvider { get; }
|
||||
public XDataServiceConfiguration DataConfiguration { get; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XTagProvider(
|
||||
IXTagRepository repository,
|
||||
IXIdentityProvider identityProvider,
|
||||
XDataServiceConfiguration dataConfiguration,
|
||||
IHubContext<XTagEntityHub> hub = null
|
||||
)
|
||||
{
|
||||
//
|
||||
Hub = hub;
|
||||
Repository = repository;
|
||||
IdentityProvider = identityProvider;
|
||||
DataConfiguration = dataConfiguration;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Helpers ....
|
||||
/// <summary>
|
||||
/// Converts an Entity to Dto ...
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public XTagDto ToDto(XTag model)
|
||||
{
|
||||
return model.ToDto();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a List of Entitiies to List of Dto's ...
|
||||
/// </summary>
|
||||
/// <param name="models"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<XTagDto> ToDtoList(IEnumerable<XTag> models)
|
||||
{
|
||||
//
|
||||
var result = new List<XTagDto>();
|
||||
|
||||
//
|
||||
if (!models.IsNull() && models.HasChild())
|
||||
{
|
||||
//
|
||||
foreach (var model in models)
|
||||
{
|
||||
//
|
||||
var dto = ToDto(model);
|
||||
if (!dto.IsNullOrDefault())
|
||||
{
|
||||
result.Add(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts Query Result of Entities to Dto ...
|
||||
/// </summary>
|
||||
/// <param name="queryResult"></param>
|
||||
/// <returns></returns>
|
||||
public XQueryResult<XTagDto> ToDtoQueryResult(XQueryResult<XTag> queryResult)
|
||||
{
|
||||
//
|
||||
var result = new XQueryResult<XTagDto>();
|
||||
|
||||
//
|
||||
if (!queryResult.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
result.Page = queryResult.Page;
|
||||
result.PageSize = queryResult.PageSize;
|
||||
result.TotalItems = queryResult.TotalItems;
|
||||
result.TotalPages = queryResult.TotalPages;
|
||||
result.TotalFilteredItems = queryResult.TotalFilteredItems;
|
||||
result.TotalFilteredPages = queryResult.TotalFilteredPages;
|
||||
|
||||
//
|
||||
if (!queryResult.Items.IsNull() && queryResult.Items.HasChild())
|
||||
{
|
||||
result.Items = ToDtoList(queryResult.Items);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Tools ...
|
||||
/// <summary>
|
||||
/// Add Specified Tag ...
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> Add(
|
||||
XTagDto model,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
XTagDto result = null;
|
||||
|
||||
//
|
||||
// Converts to Entity ...
|
||||
var entity = model.FromDto();
|
||||
if (!model.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (entity.IsNullOrDefault())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
entity = await Repository.AddAsync(entity);
|
||||
if (entity.IsNullOrDefault())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
result = ToDto(entity);
|
||||
}
|
||||
|
||||
//
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
action: XBaseEntityHubAction.Add.GetStringValue(),
|
||||
payLoad: entity.ToJSON(camelCase: true),
|
||||
connectionId: connectionId
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Specified Dto ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> Update(
|
||||
int id,
|
||||
XTagDto model,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = id.IsValidIntId();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
XTagDto result = null;
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
isValid = await IsExists(id);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var entity = await Repository.GetAsync(id);
|
||||
if (entity.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var tagEntity = model.FromDto();
|
||||
entity = entity.UpdateData(
|
||||
updateWith: tagEntity,
|
||||
propertyBlackList: new List<string>
|
||||
{
|
||||
nameof(XTagDto.Id),
|
||||
nameof(XTagDto.References)
|
||||
}
|
||||
);
|
||||
entity.References = tagEntity.References;
|
||||
entity = await Repository.UpdateAsync(id, entity);
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
result = ToDto(entity);
|
||||
}
|
||||
|
||||
//
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
action: XBaseEntityHubAction.Update.GetStringValue(),
|
||||
payLoad: entity.ToJSON(camelCase: true),
|
||||
connectionId: connectionId
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Dto ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> Remove(
|
||||
int id,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = id.IsValidIntId();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
isValid = await IsExists(id);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var entity = await Repository.RemoveAsync(id);
|
||||
|
||||
//
|
||||
XTagDto result = null;
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
result = ToDto(entity);
|
||||
}
|
||||
|
||||
//
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
||||
payLoad: entity.ToJSON(camelCase: true),
|
||||
connectionId: connectionId
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Item as Dto ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> Get(int id)
|
||||
{
|
||||
//
|
||||
var result = new XTagDto();
|
||||
if (!id.IsValidIntId())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
if (id.IsValidIntId())
|
||||
{
|
||||
//
|
||||
var entity = await Repository.GetAsync(id);
|
||||
if (entity.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
result = ToDto(entity);
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Specified Tag by it's Label ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> GetTag(string tag)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (tag.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await FindOne(e => e.Tag.ToNormalString() == tag.ToNormalString());
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve All Items as Dto ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XTagDto>> GetAll()
|
||||
{
|
||||
//
|
||||
var result = new List<XTagDto>();
|
||||
|
||||
//
|
||||
var entities = await Repository.GetAllAsync();
|
||||
if (!entities.IsNull() && entities.HasChild())
|
||||
{
|
||||
//
|
||||
result = ToDtoList(entities)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find Specified Item by Condition ...
|
||||
/// </summary>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XTagDto> FindOne(Expression<Func<XTag, bool>> whereClause)
|
||||
{
|
||||
//
|
||||
XTagDto result = null;
|
||||
|
||||
//
|
||||
var entitiy = await Repository.FindOneAsync(whereClause);
|
||||
if (!entitiy.IsNullOrDefault())
|
||||
{
|
||||
result = ToDto(entitiy);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find Many Items based on Conditions ...
|
||||
/// </summary>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XTagDto>> FindMany(Expression<Func<XTag, bool>> whereClause)
|
||||
{
|
||||
//
|
||||
var result = new List<XTagDto>();
|
||||
|
||||
//
|
||||
var entities = await Repository.FindManyAsync(whereClause);
|
||||
if (!entities.IsNull() || entities.HasChild())
|
||||
{
|
||||
//
|
||||
result = ToDtoList(entities)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Model retrieving Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XTagDto>> Query(XQuery query)
|
||||
{
|
||||
//
|
||||
var result = new XQueryResult<XTagDto>();
|
||||
|
||||
//
|
||||
var queryResult = await Repository.QueryAsync(query);
|
||||
if (!queryResult.IsNull())
|
||||
{
|
||||
result = ToDtoQueryResult(queryResult);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Conditional Retrieving Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XTagDto>> ConditionalQuery(
|
||||
XQuery query,
|
||||
Expression<Func<XTag, bool>> whereClause
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = new XQueryResult<XTagDto>();
|
||||
|
||||
//
|
||||
var queryResult = await Repository.ConditionalQueryAsync(
|
||||
query: query,
|
||||
whereClause: whereClause
|
||||
);
|
||||
if (!queryResult.IsNull())
|
||||
{
|
||||
result = ToDtoQueryResult(queryResult);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count Exists Entities ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<int> Count()
|
||||
{
|
||||
return await Repository.CountAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Entity Exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> IsExists(int id)
|
||||
{
|
||||
return await Repository.IsExistsAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Tag Exists by Label ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> IsTagExists(string tag)
|
||||
{
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
if (!tag.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
var dto = await FindOne(e => e.Tag.ToNormalString() == tag.ToNormalString());
|
||||
result = !dto.IsNullOrDefault();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Hub Actions ...
|
||||
/// <summary>
|
||||
/// Send Custom Push Message ...
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="payLoad"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SendPush(
|
||||
string action,
|
||||
string payLoad,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
var actions = new List<string>
|
||||
{
|
||||
XBaseEntityHubAction.Add.GetStringValue(),
|
||||
XBaseEntityHubAction.Update.GetStringValue(),
|
||||
XBaseEntityHubAction.Delete.GetStringValue(),
|
||||
XBaseEntityHubAction.AddMany.GetStringValue(),
|
||||
XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
||||
XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
||||
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
||||
};
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
!Hub.IsNull() &&
|
||||
!action.IsNullOrEmpty() &&
|
||||
actions.Contains(action);
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var clients = Hub.Clients.All;
|
||||
if (!connectionId.IsNullOrEmpty())
|
||||
{
|
||||
clients = Hub.Clients.AllExcept(connectionId);
|
||||
}
|
||||
try
|
||||
{
|
||||
await clients.SendAsync(action, payLoad, connectionId);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user