fix referencing issues ...
fix seeding issues ... fix SubCategory Refresh and Add Support for handle Category Referesh and Referencing ...
This commit is contained in:
@@ -73,11 +73,11 @@ namespace xCategoryService.Providers
|
||||
|
||||
//
|
||||
// Retrieve Last Index ...
|
||||
var maxIndex = (await GetReferencingIndexes(
|
||||
var indexes = await GetReferencingIndexes(
|
||||
providedForId: providedForId,
|
||||
cancellationToken: cancellationToken
|
||||
))
|
||||
.Max();
|
||||
);
|
||||
var maxIndex = indexes.HasChild() ? indexes.Max() : -1;
|
||||
if (forIndex > maxIndex)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace xCategoryService.Providers
|
||||
{
|
||||
public class XCategoryServiceSeeder
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -143,17 +143,21 @@ namespace xCategoryService.Providers
|
||||
//
|
||||
// Reading Category Resource ...
|
||||
XCategoryResourceDto categoryResourceDto = null;
|
||||
var categoryDto = await categoryProvider.GetReference(
|
||||
providedForId: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!categoryDto.IsNullOrDefault())
|
||||
try
|
||||
{
|
||||
categoryResourceDto = await categoryProvider.GetResource(
|
||||
id: categoryDto.Id,
|
||||
var categoryDto = await categoryProvider.GetReference(
|
||||
providedForId: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!categoryDto.IsNullOrDefault())
|
||||
{
|
||||
categoryResourceDto = await categoryProvider.GetResource(
|
||||
id: categoryDto.Id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
//
|
||||
var result = new XSubCategoryResourceDto
|
||||
@@ -439,7 +443,7 @@ namespace xCategoryService.Providers
|
||||
|
||||
//
|
||||
// Update Category Dto if not ...
|
||||
if (item.Item.Title.IsNullOrEmpty() ||
|
||||
if (item.Item.Title.IsNullOrEmpty() ||
|
||||
!item.Item.Title
|
||||
.Equals(
|
||||
titleResource.Resource,
|
||||
@@ -671,6 +675,17 @@ namespace xCategoryService.Providers
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove all Referencings ...
|
||||
if (isValid)
|
||||
{
|
||||
await categoryProvider.RemoveReferences(
|
||||
providedForId: id,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (isValid)
|
||||
{
|
||||
@@ -1123,6 +1138,42 @@ namespace xCategoryService.Providers
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Category ...
|
||||
if (
|
||||
!isDelete &&
|
||||
(isNew || isExists) &&
|
||||
!resource.Category.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Refresh Category ...
|
||||
var category = await categoryProvider.Refresh(
|
||||
userInfo: userInfo,
|
||||
resource: resource.Category,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Handle SubCategory Referencings ...
|
||||
var references = await categoryProvider.GetAllReferences(
|
||||
providedForId: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var hasReference =
|
||||
references.HasChild() &&
|
||||
references.Any(r => r.Id == category.Item.Id);
|
||||
if (!hasReference)
|
||||
{
|
||||
await categoryProvider.AddReference(
|
||||
providedForId: id,
|
||||
model: category.Item,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Action ...
|
||||
isValid = id.IsValidIntId();
|
||||
@@ -1162,6 +1213,7 @@ namespace xCategoryService.Providers
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get All Resources as Async Enumerable ...
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user