extends XResourceProvider and it's Related Requirements ...
This commit is contained in:
@@ -0,0 +1,394 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Extensions;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
|
||||
namespace xStringService.Providers
|
||||
{
|
||||
public abstract class XBaseResourceProvider : IXResourceProvider
|
||||
{
|
||||
protected string resource;
|
||||
private readonly IXStringServiceProvider provider;
|
||||
|
||||
protected XBaseResourceProvider(
|
||||
string resource,
|
||||
IXStringServiceProvider provider
|
||||
)
|
||||
{
|
||||
this.resource = resource;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<string>> GetLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await ExtractItems(cancellationToken))
|
||||
.Select(x => x.Language)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items ...
|
||||
/// </summary>
|
||||
/// <param name="resource">Specified Resource Title</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await ExtractItems(cancellationToken);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract Translation of in Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">Specified Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<string> GetResourceTranslation(
|
||||
string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var item = (await ExtractItems(cancellationToken))
|
||||
.FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
//
|
||||
var result = item?.TranslatedValue ?? string.Empty;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Has Specified Translation or not ...
|
||||
/// </summary>
|
||||
/// <param name="language">Specified Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<bool> HasLocale(
|
||||
string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var item = (await ExtractItems(cancellationToken))
|
||||
.FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
//
|
||||
var result = !item.IsNullOrDefault();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve as Locale Model ...
|
||||
/// </summary>
|
||||
/// <param name="language">Specified Language ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XLocaleResourceDto> GetLocale(
|
||||
string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var item = (await ExtractItems(cancellationToken))
|
||||
.FirstOrDefault(x => x.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
//
|
||||
var result =
|
||||
!item.IsNullOrDefault()
|
||||
? item.ToXLocaleResourceDto()
|
||||
: null;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Locale Models ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await ExtractItems(cancellationToken))
|
||||
.Select(x => x.ToXLocaleResourceDto())
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve as XResourceDto ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XResourceDto> GetResource(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var locales = await GetLocales();
|
||||
|
||||
//
|
||||
var result = new XResourceDto
|
||||
{
|
||||
Locales = locales,
|
||||
Resource = resource,
|
||||
};
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or Update a Resource Model ...
|
||||
/// </summary>
|
||||
/// <param name="resource">a XResourceDto Model ...</param>
|
||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XResourceDto> AddOrUpdateResource(
|
||||
XResourceDto resource,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var isValid =
|
||||
!resource.IsNullOrDefault() &&
|
||||
resource.Resource == this.resource;
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Exists Resource ...
|
||||
var result = await GetResource(cancellationToken);
|
||||
isValid = !result.IsNullOrDefault() && result.Locales.HasChild();
|
||||
if (isValid)
|
||||
{
|
||||
await RemoveResource(
|
||||
resource: result,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
foreach (var locale in resource.Locales)
|
||||
{
|
||||
//
|
||||
var item = new XStringDto
|
||||
{
|
||||
Language = locale.Language,
|
||||
ResourceTitle = this.resource,
|
||||
TranslatedValue = locale.Value,
|
||||
};
|
||||
|
||||
//
|
||||
await provider.AddAsync(
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
result = await GetResource(cancellationToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Locale ...
|
||||
/// </summary>
|
||||
/// <param name="locale"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XResourceDto> AddOrUpdateLocale(
|
||||
XLocaleResourceDto locale,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var item = (await ExtractItems(cancellationToken))
|
||||
.FirstOrDefault(x =>
|
||||
x.ResourceTitle == resource &&
|
||||
x.Language == locale.Language);
|
||||
var isExists = !item.IsNullOrDefault();
|
||||
if (isExists)
|
||||
{
|
||||
item.TranslatedValue = locale.Value;
|
||||
item = await provider.UpdateAsync(
|
||||
item: item,
|
||||
id: item.Id,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = new XStringDto
|
||||
{
|
||||
ResourceTitle = resource,
|
||||
Language = locale.Language,
|
||||
TranslatedValue = locale.Value
|
||||
};
|
||||
item = await provider.AddAsync(
|
||||
item: item,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
var result = await GetResource(cancellationToken);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Locale ...
|
||||
/// </summary>
|
||||
/// <param name="locale"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XResourceDto> RemoveLocale(
|
||||
XLocaleResourceDto locale,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var item = (await ExtractItems(cancellationToken))
|
||||
.FirstOrDefault(x =>
|
||||
x.ResourceTitle == resource &&
|
||||
x.Language == locale.Language);
|
||||
var isExists = !item.IsNullOrDefault();
|
||||
if (isExists)
|
||||
{
|
||||
await provider.RemoveAsync(
|
||||
id: item.Id,
|
||||
softDelete: false,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
var result = await GetResource(cancellationToken);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Resource Model ...
|
||||
/// </summary>
|
||||
/// <param name="resource">a XResourceDto Model ...</param>
|
||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task RemoveResource(
|
||||
XResourceDto resource,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var items = await ExtractItems(cancellationToken);
|
||||
|
||||
//
|
||||
foreach (var item in items)
|
||||
{
|
||||
//
|
||||
await provider.RemoveAsync(
|
||||
id: item.Id,
|
||||
softDelete: false,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Provate ...
|
||||
private async Task<IEnumerable<XStringDto>> ExtractItems(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await provider.FindManyAsync(
|
||||
includeBuilder: null,
|
||||
ignoreSoftDeleteds: true,
|
||||
orderBuilder: x => x
|
||||
.OrderBy(y => y.Language)
|
||||
.ThenBy(y => y.ResourceTitle),
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x =>
|
||||
x.ResourceTitle.Equals(resource, StringComparison.InvariantCultureIgnoreCase)
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
// public void SetResourceTitle(string resource)
|
||||
// {
|
||||
// this.resource = resource;
|
||||
// }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using xModels.Dtos;
|
||||
using xPushService.Providers;
|
||||
using xStringService.Extensions;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Interfaces.Dtos;
|
||||
using xStringService.Models.Dtos;
|
||||
using xStringService.Models.Entities;
|
||||
using xStringService.Providers.Dtos;
|
||||
|
||||
namespace xStringService.Providers
|
||||
{
|
||||
public class XStringProvider : XBaseProvided<XString, XStringDto, int, XStringDtoHub>, IXStringProvider
|
||||
{
|
||||
public XStringProvider(
|
||||
IXStringServiceProvider provider
|
||||
) : base(
|
||||
provider,
|
||||
permittedRoles: new string[] { }
|
||||
)
|
||||
{ }
|
||||
|
||||
public override bool IsOwned(
|
||||
XStringDto item,
|
||||
XUserClaimsInfoDto userInfo
|
||||
)
|
||||
{
|
||||
return !item.IsNullOrDefault();
|
||||
}
|
||||
|
||||
public override bool IsOwned(
|
||||
XString item,
|
||||
XUserClaimsInfoDto userInfo
|
||||
)
|
||||
{
|
||||
return !item.IsNullOrDefault();
|
||||
}
|
||||
|
||||
//
|
||||
#region Tools ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages ...
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<string>> GetLanguages(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await GetAll(
|
||||
includeBuilder: null,
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder: x => x.OrderBy(y => y.Language)
|
||||
))
|
||||
.Select(x => x.Language)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a List of Resource Titles ...
|
||||
/// </summary>
|
||||
/// <param name="language">if provided, returns all language Specified resource titles, if not, all Resource Titles</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<string>> GetResourceTitles(
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await FindMany(
|
||||
includeBuilder: null,
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder: x => x.OrderBy(y => y.ResourceTitle),
|
||||
predicate: x =>
|
||||
string.IsNullOrWhiteSpace(language) ||
|
||||
x.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase)
|
||||
))
|
||||
.Select(x => x.ResourceTitle)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items which belongs to Specified Resource Title ...
|
||||
/// </summary>
|
||||
/// <param name="resource">Specified Resource Title</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XStringDto>> GetResourceLocales(
|
||||
string resource,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await FindMany(
|
||||
includeBuilder: null,
|
||||
cancellationToken: cancellationToken,
|
||||
orderBuilder: x => x.OrderBy(y => y.Language),
|
||||
predicate: x =>
|
||||
!string.IsNullOrWhiteSpace(resource) &&
|
||||
resource.Equals(x.ResourceTitle, System.StringComparison.InvariantCultureIgnoreCase)
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract Translation of a Resource in Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="language">Specified Language ...</param>
|
||||
/// <param name="resource">Specified Resource Title ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetResourceTranslation(
|
||||
string language,
|
||||
string resource,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await FindOne(
|
||||
includeBuilder: null,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x =>
|
||||
!string.IsNullOrWhiteSpace(language) &&
|
||||
!string.IsNullOrWhiteSpace(resource) &&
|
||||
x.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase) &&
|
||||
x.ResourceTitle.Equals(resource, System.StringComparison.InvariantCultureIgnoreCase)
|
||||
))?
|
||||
.TranslatedValue ?? "";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a Resource as Locale Model ...
|
||||
/// </summary>
|
||||
/// <param name="language">Specified Language ...</param>
|
||||
/// <param name="resource">Specified Resource Title ...</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XLocaleResourceDto> GetLocale(
|
||||
string language,
|
||||
string resource,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await FindOne(
|
||||
includeBuilder: null,
|
||||
cancellationToken: cancellationToken,
|
||||
predicate: x =>
|
||||
!string.IsNullOrWhiteSpace(language) &&
|
||||
!string.IsNullOrWhiteSpace(resource) &&
|
||||
x.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase) &&
|
||||
x.ResourceTitle.Equals(resource, System.StringComparison.InvariantCultureIgnoreCase)
|
||||
))?
|
||||
.ToXLocaleResourceDto() ?? null;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Resource Instances as Locale Models ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XLocaleResourceDto>> GetLocales(
|
||||
string resource,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = (await GetResourceLocales(
|
||||
resource: resource,
|
||||
cancellationToken: cancellationToken
|
||||
))
|
||||
.ToList()
|
||||
.Select(x => x.ToXLocaleResourceDto())
|
||||
.ToList();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Locales of Specified Resource and Represent as XResourceDto ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XResourceDto> GetResource(
|
||||
string resource,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XResourceDto result = null;
|
||||
|
||||
//
|
||||
// Validate Resource ...
|
||||
if (resource.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Locales of Resource ...
|
||||
var locales = await GetLocales(
|
||||
resource: resource,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
result = new XResourceDto
|
||||
{
|
||||
Locales = locales,
|
||||
Resource = resource,
|
||||
};
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add or Update a Resource Model ...
|
||||
/// </summary>
|
||||
/// <param name="resource">a XResourceDto Model ...</param>
|
||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XResourceDto> AddOrUpdateResource(
|
||||
XResourceDto resource,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
XResourceDto result = null;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
var isValid =
|
||||
!resource.IsNullOrDefault() &&
|
||||
!resource.Resource.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Permissions ...
|
||||
isValid =
|
||||
userInfo.IsNullOrDefault() ||
|
||||
HasPermision(userInfo);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Remove all Resources if Exists ...
|
||||
result = await GetResource(
|
||||
resource: resource.Resource,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var isExists = !result.IsNullOrDefault();
|
||||
if (isExists)
|
||||
{
|
||||
//
|
||||
await RemoveResource(
|
||||
resource: result,
|
||||
userInfo: userInfo,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through all Exists Locales and Add them ...
|
||||
foreach (var locale in resource.Locales)
|
||||
{
|
||||
//
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
var item = new XStringDto
|
||||
{
|
||||
Language = locale.Language,
|
||||
TranslatedValue = locale.Value,
|
||||
ResourceTitle = resource.Resource,
|
||||
};
|
||||
await Add(
|
||||
item: item,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Reload Result after Updates ...
|
||||
result = await GetResource(
|
||||
resource: resource.Resource,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Resource Model ...
|
||||
/// </summary>
|
||||
/// <param name="resource">a XResourceDto Model ...</param>
|
||||
/// <param name="userInfo">Actor User for Permissions ...</param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task RemoveResource(
|
||||
XResourceDto resource,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !resource.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var items = await GetResourceLocales(
|
||||
resource: resource.Resource,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
isValid =
|
||||
!items.IsNullOrDefault() &&
|
||||
items.HasChild();
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
foreach (var item in items)
|
||||
{
|
||||
//
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
await Remove(
|
||||
id: item.Id,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user