diff --git a/Providers/XCategoryProvider.cs b/Providers/XCategoryProvider.cs
index 1617ac5..48afff3 100644
--- a/Providers/XCategoryProvider.cs
+++ b/Providers/XCategoryProvider.cs
@@ -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();
}
+ ///
+ /// Check a Category Has Specified Locale or not ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task 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;
+ }
+
///
/// Load an Item by all of it's Related Translations ...
///
@@ -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;
}
+ ///
+ /// Update a Category Item for Specified Language ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public async Task 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 ...
+
+ }
}
}
\ No newline at end of file