last ...
This commit is contained in:
+296
-86
@@ -88,7 +88,7 @@ namespace xCategoryService.Providers
|
||||
var isValid =
|
||||
id.IsValidIntId() &&
|
||||
!language.IsNullOrEmpty();
|
||||
if (isValid)
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace xCategoryService.Providers
|
||||
identifier: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var descriptionResource = await titleResourceProvider.GetResource(
|
||||
var descriptionResource = await descriptionResourceProvider.GetResource(
|
||||
identifier: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -289,6 +289,189 @@ namespace xCategoryService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Item for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="language">if null, Remove All</param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XCategoryResourceDto> Remove(
|
||||
int id,
|
||||
string language = null,
|
||||
string connectionId = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = id.IsValidIntId();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Item Exists ...
|
||||
isValid = await IsExists(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Locale if Provided ...
|
||||
isValid =
|
||||
language.IsNullOrEmpty() ||
|
||||
await HasLocale(
|
||||
id: id,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (language.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
// Remove All ...
|
||||
|
||||
//
|
||||
// Titles ...
|
||||
await titleResourceProvider.RemoveLocales(
|
||||
identifier: id,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Descriptions ...
|
||||
await descriptionResourceProvider.RemoveLocales(
|
||||
identifier: id,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Remove Entity ...
|
||||
await provider.RemoveAsync(
|
||||
id: id,
|
||||
softDelete: false,
|
||||
saveChanges: true,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
isValid = true;
|
||||
result.Titles.Locales = [];
|
||||
result.Descriptions.Locales = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Remove Only One Locale, and if there is one, Remove all ...
|
||||
|
||||
//
|
||||
// Remove Title if Exists ...
|
||||
isValid = await titleResourceProvider.HasLocale(
|
||||
identifier: id,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.RemoveLocale(
|
||||
identifier: id,
|
||||
language: language,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Remove Description if Exists ...
|
||||
isValid = await descriptionResourceProvider.HasLocale(
|
||||
identifier: id,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.RemoveLocale(
|
||||
identifier: id,
|
||||
language: language,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Resource ...
|
||||
result = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Check Has Locales ...
|
||||
isValid = result.Titles.Locales.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
//
|
||||
// Remove Item ...
|
||||
await provider.RemoveAsync(
|
||||
id: id,
|
||||
softDelete: false,
|
||||
saveChanges: true,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
result.Titles.Locales = [];
|
||||
result.Descriptions.Locales = [];
|
||||
}
|
||||
|
||||
//
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
//
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Send Push ...
|
||||
await provider.SendPush(
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
payLoad: result.ToJSON(camelCase: true),
|
||||
action:
|
||||
result.Titles.Locales.HasChild()
|
||||
? "DeleteLocale"
|
||||
: XBaseEntityHubAction.Delete.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update an Item for Specified Language ...
|
||||
/// </summary>
|
||||
@@ -460,6 +643,7 @@ namespace xCategoryService.Providers
|
||||
|
||||
//
|
||||
var id = -1;
|
||||
var isDelete = false;
|
||||
XCategoryResourceDto result = null;
|
||||
|
||||
//
|
||||
@@ -564,7 +748,7 @@ namespace xCategoryService.Providers
|
||||
// Add Descriptions ...
|
||||
await descriptionResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
locale: desLocale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -581,109 +765,130 @@ namespace xCategoryService.Providers
|
||||
// Try to Refresh Resource State ...
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
//
|
||||
// Titles ...
|
||||
var removeTitles = result.Titles.Locales.Where(
|
||||
l => !resource.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in removeTitles)
|
||||
// Check Delete ...
|
||||
isDelete = !resource.Titles.Locales.HasChild();
|
||||
if (isDelete)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.RemoveLocale(
|
||||
identifier: id,
|
||||
// Handle Delete ...
|
||||
await Remove(
|
||||
id: id,
|
||||
language: null,
|
||||
userInfo: userInfo,
|
||||
connectionId: null,
|
||||
language: locale.Language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Handle Update ...
|
||||
|
||||
//
|
||||
// Descriptions ...
|
||||
var removeDescriptions = result.Descriptions.Locales.Where(
|
||||
l => !resource.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in removeDescriptions)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.RemoveLocale(
|
||||
identifier: id,
|
||||
connectionId: null,
|
||||
language: locale.Language,
|
||||
cancellationToken: cancellationToken
|
||||
#region Remove ...
|
||||
//
|
||||
// Titles ...
|
||||
var removeTitles = result.Titles.Locales.Where(
|
||||
l => !resource.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
foreach (var locale in removeTitles)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.RemoveLocale(
|
||||
identifier: id,
|
||||
connectionId: null,
|
||||
language: locale.Language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
//
|
||||
// Titles ...
|
||||
var updateTitles = result.Titles.Locales.Where(
|
||||
l => resource.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in updateTitles)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
// Descriptions ...
|
||||
var removeDescriptions = result.Descriptions.Locales.Where(
|
||||
l => !resource.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
}
|
||||
foreach (var locale in removeDescriptions)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.RemoveLocale(
|
||||
identifier: id,
|
||||
connectionId: null,
|
||||
language: locale.Language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
// Descriptions ...
|
||||
var updateDescriptions = result.Descriptions.Locales.Where(
|
||||
l => resource.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in updateDescriptions)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
#region Update ...
|
||||
//
|
||||
// Titles ...
|
||||
var updateTitles = result.Titles.Locales.Where(
|
||||
l => resource.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
foreach (var locale in updateTitles)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region New ...
|
||||
//
|
||||
// Titles ...
|
||||
var newTitles = resource.Titles.Locales.Where(
|
||||
l => !result.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in newTitles)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
// Descriptions ...
|
||||
var updateDescriptions = result.Descriptions.Locales.Where(
|
||||
l => resource.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
}
|
||||
foreach (var locale in updateDescriptions)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
// Descriptions ...
|
||||
var newDescriptions = resource.Descriptions.Locales.Where(
|
||||
l => !result.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in newDescriptions)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
#region New ...
|
||||
//
|
||||
// Titles ...
|
||||
var newTitles = resource.Titles.Locales.Where(
|
||||
l => !result.Titles.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in newTitles)
|
||||
{
|
||||
//
|
||||
await titleResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Descriptions ...
|
||||
var newDescriptions = resource.Descriptions.Locales.Where(
|
||||
l => !result.Descriptions.Locales.Any(r => r.Language.Equals(l.Language, System.StringComparison.InvariantCultureIgnoreCase))
|
||||
);
|
||||
foreach (var locale in newDescriptions)
|
||||
{
|
||||
//
|
||||
await descriptionResourceProvider.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: locale,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
//
|
||||
@@ -696,7 +901,10 @@ namespace xCategoryService.Providers
|
||||
|
||||
//
|
||||
// Get Result ...
|
||||
result = await GetResource(
|
||||
result =
|
||||
isDelete
|
||||
? resource
|
||||
: await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -713,7 +921,9 @@ namespace xCategoryService.Providers
|
||||
payLoad: result.ToJSON(camelCase: true),
|
||||
action: isNew
|
||||
? XBaseEntityHubAction.Add.GetStringValue()
|
||||
: XBaseEntityHubAction.Update.GetStringValue()
|
||||
: isDelete
|
||||
? XBaseEntityHubAction.Delete.GetStringValue()
|
||||
: XBaseEntityHubAction.Update.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user