last ...
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCategoryService.Interfaces;
|
||||
@@ -10,6 +11,7 @@ using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using xModels.Dtos;
|
||||
using xPushService.Constants;
|
||||
using xPushService.Providers;
|
||||
|
||||
namespace xCategoryService.Providers
|
||||
@@ -54,6 +56,51 @@ namespace xCategoryService.Providers
|
||||
return !item.IsNullOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a Category Has Specified Locale or not ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> HasLocale(
|
||||
int id,
|
||||
string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
id.IsValidIntId() &&
|
||||
!language.IsNullOrEmpty();
|
||||
if (isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Resource ...
|
||||
var resource = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Check Result ...
|
||||
var result =
|
||||
!resource.IsNullOrDefault() &&
|
||||
resource.Titles.Locales
|
||||
.Any(x => x.Language
|
||||
.Equals(language, System.StringComparison.InvariantCultureIgnoreCase)) &&
|
||||
resource.Descriptions.Locales
|
||||
.Any(x => x.Language
|
||||
.Equals(language, System.StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an Item by all of it's Related Translations ...
|
||||
/// </summary>
|
||||
@@ -179,7 +226,7 @@ namespace xCategoryService.Providers
|
||||
id: id,
|
||||
item: item,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
connectionId: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
@@ -203,17 +250,86 @@ namespace xCategoryService.Providers
|
||||
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>
|
||||
/// Update a Category Item for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XCategoryResourceDto> Update(
|
||||
int id,
|
||||
XCategoryDto item,
|
||||
string langauge = null,
|
||||
string language = null,
|
||||
string connectionId = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
) {}
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid =
|
||||
id.IsValidIntId() &&
|
||||
!item.IsNullOrDefault() &&
|
||||
!language.IsNullOrEmpty() &&
|
||||
!item.Title.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Category Exists ...
|
||||
isValid = await IsExists(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Locale Exists ...
|
||||
isValid = await HasLocale(
|
||||
id: id,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve Exists Item Resource ...
|
||||
var resource = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Here we can Use Exists Title and Description for Access Resource Titles ...
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user