This commit is contained in:
2025-12-18 15:59:08 +03:30
parent 82a1936a9d
commit 6519f5a0bd
+30 -52
View File
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
@@ -126,39 +127,15 @@ namespace xTagService.Providers
.AsEnumerable();
//
var dtos = new List<XTagDto>();
var result = new List<XTagDto>();
foreach (var entity in entities)
{
//
var dto = entity.ToDto();
if (!dto.IsNullOrDefault())
{
dtos.Add(dto);
}
}
//
List<XTagDto> result = dtos;
if (dtos.HasChild())
{
//
// Sorting Result Based on Indexes ...
var lastIndex = GetLastIndex(providedForId);
if (lastIndex > 0)
{
//
result.Clear();
for (int i = 0; i <= lastIndex; i++)
{
//
var dto = dtos
.FirstOrDefault(d => d.References
.Any(dr => dr.Index == i && dr.ReferencedTo == $"{providedForId}"));
if (!dto.IsNullOrDefault())
{
result.Add(dto);
}
}
result.Add(dto);
}
}
@@ -290,7 +267,7 @@ namespace xTagService.Providers
//
var lastIndex = GetLastIndex(providedForId);
if (lastIndex == 0)
if (lastIndex == -1)
{
//
// This Means there isnot any Reference ...
@@ -305,29 +282,16 @@ namespace xTagService.Providers
else
{
//
// Check Provided Index Exists or not ...
var isExists = model.References.Any(r => r.Index == forIndex);
if (!isExists)
{
//
// Normalize For Index ...
if (forIndex > lastIndex + 1)
{
forIndex = lastIndex + 1;
}
forIndex = lastIndex + 1;
//
// Add New Reference ...
model.References.Add(new XReference<string>
{
Index = forIndex,
ProvidedFor = Provider,
ReferencedTo = $"{providedForId}"
});
}
else
//
// Add New Reference ...
model.References.Add(new XReference<string>
{
}
Index = forIndex,
ProvidedFor = Provider,
ReferencedTo = $"{providedForId}"
});
}
//
@@ -560,7 +524,21 @@ namespace xTagService.Providers
result = IsExists(tag);
if (!result)
{
XException.NotFound.Throw();
//
// Create Tag if Not Exists ...
var tagDto = new XTagDto
{
Tag = tag,
};
tagDto = await TagProvider.Add(
model: tagDto,
connectionId: connectionId
);
result = !tagDto.IsNullOrDefault();
if (!result)
{
XException.ActionFailed.Throw();
}
}
//
@@ -774,7 +752,7 @@ namespace xTagService.Providers
private int GetLastIndex(TKey providedForId)
{
//
var result = 0;
var result = -1;
//
// Validate ...
@@ -796,7 +774,7 @@ namespace xTagService.Providers
.AsEnumerable();
if (all.IsNull() || !all.HasChild())
{
result = 0;
result = -1;
}
else
{
@@ -811,7 +789,7 @@ namespace xTagService.Providers
}
else
{
result = 0;
result = -1;
}
}