This commit is contained in:
2026-06-10 09:31:49 +03:30
parent f0febb0b9c
commit 45e6bf1362
3 changed files with 265 additions and 2 deletions
+151 -1
View File
@@ -319,6 +319,32 @@ namespace xCategoryService.Providers
language: language,
cancellationToken: cancellationToken
);
if (!isValid)
{
XException.NotFound.Throw();
}
//
// Retrieve Category Dto for Validate Owining ...
var dto = await Get(
id: id,
includeBuilder: null,
cancellationToken: cancellationToken
);
//
// Check Permission ...
isValid =
!dto.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
IsOwned(
item: dto,
userInfo: userInfo
);
if (!isValid)
{
XException.NotAllowed.Throw();
}
//
// Retrieve Exists Item Resource ...
@@ -328,8 +354,132 @@ namespace xCategoryService.Providers
);
//
// Here we can Use Exists Title and Description for Access Resource Titles ...
var titleUpdated = false;
var descriptionUpdated = false;
//
// Update Title ...
resource.Titles.Locales
.ToList()
.ForEach(tl =>
{
//
if (tl.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase))
{
//
titleUpdated = true;
tl.Value = item.Title;
}
});
//
// Update Description ...
resource.Descriptions.Locales
.ToList()
.ForEach(dl =>
{
//
if (dl.Language.Equals(language, System.StringComparison.InvariantCultureIgnoreCase))
{
//
descriptionUpdated = true;
dl.Value = item.Description;
}
});
//
// Validate Title and Description Updated ...
isValid = titleUpdated && descriptionUpdated;
if (!isValid)
{
XException.ActionFailed.Throw();
}
//
resource = await RefereshResource(
resource: resource,
userInfo: userInfo,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
return resource;
}
/// <summary>
/// Referesh a Resource ...
/// </summary>
/// <param name="resource"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XCategoryResourceDto> RefereshResource(
XCategoryResourceDto resource,
string connectionId = null,
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
var isValid =
!resource.IsNull() &&
!resource.Item.IsNullOrDefault();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
var id = -1;
//
// Check Item Exists ...
XCategoryDto dto =
!resource.Item.Id.IsValidIntId()
? null
: await Get(
id: resource.Item.Id,
includeBuilder: null,
cancellationToken: cancellationToken
);
var isExists = !dto.IsNullOrDefault();
//
// Do Referesh Based on Existance ...
var isNew =
!isExists &&
!resource.Item.Id.IsValidIntId();
if (isNew)
{
//
// Add ...
}
else if (isExists)
{
//
// Re State ...
id = resource.Item.Id;
}
//
isValid = id.IsValidIntId();
if (!isValid)
{
XException.ActionFailed.Throw();
}
//
// Get Result ...
var result = await GetResource(
id: id,
cancellationToken: cancellationToken
);
//
return result;
}
}
}