last ...
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCategoryService.Interfaces;
|
using xCategoryService.Interfaces;
|
||||||
@@ -10,6 +11,7 @@ using xCommons.Extensions;
|
|||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityModels.Models;
|
using xIdentityModels.Models;
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
|
using xPushService.Constants;
|
||||||
using xPushService.Providers;
|
using xPushService.Providers;
|
||||||
|
|
||||||
namespace xCategoryService.Providers
|
namespace xCategoryService.Providers
|
||||||
@@ -54,6 +56,51 @@ namespace xCategoryService.Providers
|
|||||||
return !item.IsNullOrDefault();
|
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>
|
/// <summary>
|
||||||
/// Load an Item by all of it's Related Translations ...
|
/// Load an Item by all of it's Related Translations ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -179,7 +226,7 @@ namespace xCategoryService.Providers
|
|||||||
id: id,
|
id: id,
|
||||||
item: item,
|
item: item,
|
||||||
userInfo: userInfo,
|
userInfo: userInfo,
|
||||||
connectionId: connectionId,
|
connectionId: null,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -203,17 +250,86 @@ namespace xCategoryService.Providers
|
|||||||
cancellationToken: cancellationToken
|
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;
|
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(
|
public async Task<XCategoryResourceDto> Update(
|
||||||
int id,
|
int id,
|
||||||
XCategoryDto item,
|
XCategoryDto item,
|
||||||
string langauge = null,
|
string language = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
CancellationToken cancellationToken = default
|
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