fix Category and SubCategory Referencing and Providers ...
This commit is contained in:
@@ -135,7 +135,7 @@ namespace xCategoryService.Providers
|
||||
identifier: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var descriptionResource = await titleResourceProvider.GetResource(
|
||||
var descriptionResource = await descriptionResourceProvider.GetResource(
|
||||
identifier: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -307,6 +307,207 @@ namespace xCategoryService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Item by it's Locales and Reference ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XSubCategoryResourceDto> AddResource(
|
||||
XSubCategoryResourceDto item,
|
||||
string connectionId = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
!item.IsNullOrDefault() &&
|
||||
!item.Titles.IsNullOrDefault() &&
|
||||
item.Titles.Locales.HasChild() &&
|
||||
!item.Titles.Locales.Any(tl =>
|
||||
tl.Value.IsNullOrEmpty() ||
|
||||
tl.Language.IsNullOrEmpty());
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
if (item.Item.IsNullOrDefault())
|
||||
{
|
||||
item.Item = new XSubCategoryDto();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Permission ...
|
||||
isValid = HasPermision(userInfo);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var id = -1;
|
||||
try
|
||||
{
|
||||
//
|
||||
// Handle Category Generation ...
|
||||
if (!item.Category.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Handle Category ...
|
||||
try
|
||||
{
|
||||
// Try to Add Category ...
|
||||
item.Category = await categoryProvider.Refresh(
|
||||
resource: item.Category,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
//
|
||||
// Add SubCategory for ID Generation ...
|
||||
item.Item = await base.Add(
|
||||
item: item.Item,
|
||||
userInfo: userInfo,
|
||||
connectionId: null, // Since here We dont want notification ...
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
isValid = !item.Item.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
id = item.Item.Id;
|
||||
|
||||
//
|
||||
foreach (var il in item.Titles.Locales)
|
||||
{
|
||||
//
|
||||
var title = il.Value;
|
||||
var language = il.Language;
|
||||
|
||||
//
|
||||
var descriptionItem =
|
||||
item.Descriptions.IsNullOrDefault() ||
|
||||
!item.Descriptions.Locales.HasChild()
|
||||
? null
|
||||
: item.Descriptions.Locales
|
||||
.FirstOrDefault(ides =>
|
||||
ides.Language
|
||||
.Equals(
|
||||
language,
|
||||
StringComparison.InvariantCultureIgnoreCase));
|
||||
var description =
|
||||
descriptionItem.IsNullOrDefault()
|
||||
? string.Empty
|
||||
: descriptionItem.Value;
|
||||
|
||||
//
|
||||
// Try to Add Resources ...
|
||||
var titleResource = await titleResourceProvider
|
||||
.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: new XLocaleResourceDto
|
||||
{
|
||||
Value = title,
|
||||
Language = language
|
||||
},
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var descriptionResource = await descriptionResourceProvider
|
||||
.AddOrUpdateLocale(
|
||||
identifier: id,
|
||||
locale: new XLocaleResourceDto
|
||||
{
|
||||
Value = description,
|
||||
Language = language
|
||||
},
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Update Category Dto if not ...
|
||||
if (item.Item.Title.IsNullOrEmpty() ||
|
||||
!item.Item.Title
|
||||
.Equals(
|
||||
titleResource.Resource,
|
||||
StringComparison.InvariantCultureIgnoreCase)
|
||||
)
|
||||
{
|
||||
//
|
||||
item.Item.Title = titleResource.Resource;
|
||||
item.Item.Description = descriptionResource.Resource;
|
||||
item.Item = await base.Update(
|
||||
id: id,
|
||||
item: item.Item,
|
||||
userInfo: userInfo,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Id ...
|
||||
isValid = id.IsValidIntId();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Add Resource Reference to Category ...
|
||||
isValid = await categoryProvider.AddReference(
|
||||
providedForId: id,
|
||||
connectionId: null,
|
||||
model: item.Category.Item,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve Category Resourv=ce ...
|
||||
var result = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Sending Push Notification ...
|
||||
isValid =
|
||||
isValid &&
|
||||
!result.IsNullOrDefault();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
await provider.SendPush(
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken,
|
||||
payLoad: result.ToJSON(camelCase: true),
|
||||
action: XBaseEntityHubAction.Add.GetStringValue()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Item for Specified Language ...
|
||||
/// </summary>
|
||||
@@ -867,7 +1068,7 @@ namespace xCategoryService.Providers
|
||||
//
|
||||
// Descriptions ...
|
||||
var updateDescriptions = result.Descriptions.Locales.Where(
|
||||
l => resource.Descriptions.Locales.Any(r =>
|
||||
l => resource.Descriptions.Locales.Any(r =>
|
||||
r.Value
|
||||
.Equals(l.Value, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
r.Language
|
||||
|
||||
Reference in New Issue
Block a user