resolve tagging index issues ...
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -70,8 +71,8 @@ namespace xTagService.Providers
|
||||
|
||||
//
|
||||
// Retrieve Last Index ...
|
||||
var referencesCount = await CountReferences(providedForId);
|
||||
if (forIndex > referencesCount - 1)
|
||||
var maxIndex = (await GetReferencingIndexes(providedForId)).Max();
|
||||
if (forIndex > maxIndex)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
@@ -142,22 +143,40 @@ namespace xTagService.Providers
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
var isValid =
|
||||
!providedForId.IsNull();
|
||||
if (!isValid)
|
||||
if (!isValid)
|
||||
{
|
||||
xExceptios.InvalidArgs.Throw();
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var identifier = GetProvidedID(providedForId);
|
||||
|
||||
//
|
||||
var result = TagProvider.Repository
|
||||
.AsQueryable()
|
||||
.Where(te => te.References.Contains(identifier))
|
||||
.Select(te => te.References)
|
||||
;
|
||||
IEnumerable<XReference<TKey>> result = new List<XReference<TKey>>();
|
||||
try
|
||||
{
|
||||
//
|
||||
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()
|
||||
;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
Console.WriteLine($"{ex}");
|
||||
}
|
||||
|
||||
//
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -419,6 +438,10 @@ namespace xTagService.Providers
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Referencing Indexes ...
|
||||
var indexes = await GetReferencingIndexes(providedForId);
|
||||
|
||||
//
|
||||
// Check Model Reference to ID ...
|
||||
var referencesCount = await CountReferences(providedForId);
|
||||
@@ -463,13 +486,21 @@ namespace xTagService.Providers
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Reading All References ...
|
||||
// var references = await GetAllReferences(providedForId);
|
||||
|
||||
//
|
||||
// Get Max Exists Indexes ...
|
||||
var maxIndex = indexes.Max();
|
||||
|
||||
//
|
||||
// Here We Have to Re Arrange Indexed ...
|
||||
if (reference.Index < referencesCount - 1)
|
||||
if (reference.Index < maxIndex)
|
||||
{
|
||||
//
|
||||
var startIndex = reference.Index + 1;
|
||||
for (int i = startIndex; i < referencesCount; i++)
|
||||
for (int i = startIndex; i <= maxIndex; i++)
|
||||
{
|
||||
//
|
||||
var dto = await GetReference(
|
||||
@@ -825,6 +856,38 @@ namespace xTagService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<int>> GetReferencingIndexes(TKey providedForId)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
!providedForId.IsNull();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = new List<int>();
|
||||
var referencings = await GetAllReferencings(providedForId);
|
||||
isValid = !referencings.IsNull() &&
|
||||
referencings.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
referencings
|
||||
.OrderBy(r => r.Index)
|
||||
.Select(r => r.Index)
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
private XTagDto GetTagByTag(string tag)
|
||||
{
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user