last ...
This commit is contained in:
@@ -1,10 +1,41 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCategoryService.Models.Dtos;
|
||||
using xCategoryService.Models.Entities;
|
||||
using xCategoryService.Providers.Dtos;
|
||||
using xIdentityModels.Models;
|
||||
using xPushService.Interfaces;
|
||||
|
||||
namespace xCategoryService.Interfaces
|
||||
{
|
||||
public interface IXCategoryProvider : IXBaseProvided<XCategory, XCategoryDto, int, XCategoryDtoHub>
|
||||
{ }
|
||||
{
|
||||
/// <summary>
|
||||
/// Load an Item by all of it's Related Translations ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XCategoryResourceDto> GetResource(
|
||||
int id,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Category Item for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="langauge"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XCategoryResourceDto> Add(
|
||||
XCategoryDto item,
|
||||
string langauge = null,
|
||||
string connectionId = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using xCategoryService.Models.Dtos;
|
||||
using xModels.Base;
|
||||
using xModels.Dtos;
|
||||
|
||||
namespace xCategoryService.Providers.Dtos
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent a Category by all of it's Resources ...
|
||||
/// </summary>
|
||||
public class XCategoryResourceDto : XBaseDto
|
||||
{
|
||||
public XCategoryDto Item { get; set; }
|
||||
public XResourceDto Titles { get; set; }
|
||||
public XResourceDto Descriptions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,3 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xCategoryService.Interfaces;
|
||||
@@ -56,35 +53,54 @@ namespace xCategoryService.Providers
|
||||
return !item.IsNullOrDefault();
|
||||
}
|
||||
|
||||
// public async Task<(string, string)> LoadResources(
|
||||
// int id,
|
||||
// string language = null
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// // Normalize Language ...
|
||||
// language =
|
||||
// !language.IsNullOrEmpty()
|
||||
// ? language
|
||||
// : appConfiguration.DefaultLanguage;
|
||||
/// <summary>
|
||||
/// Load an Item by all of it's Related Translations ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XCategoryResourceDto> GetResource(
|
||||
int id,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var category = await Get(
|
||||
id: id,
|
||||
includeBuilder: null,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var titleResource = await titleResourceProvider.GetResource(
|
||||
identifier: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var descriptionResource = await titleResourceProvider.GetResource(
|
||||
identifier: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
// //
|
||||
// // Validate Args ...
|
||||
// var isValid =
|
||||
// id.IsValidIntId() &&
|
||||
// !language.IsNullOrEmpty();
|
||||
// if (!isValid)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
//
|
||||
var result = new XCategoryResourceDto
|
||||
{
|
||||
Item = category,
|
||||
Titles = titleResource,
|
||||
Descriptions = descriptionResource
|
||||
};
|
||||
|
||||
// //
|
||||
// // Reading Resources ...
|
||||
// // var title = await titleResourceProvider.GetResourceLocales()
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> Add(
|
||||
/// <summary>
|
||||
/// Add Category Item for Specified Language ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="langauge"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XCategoryResourceDto> Add(
|
||||
XCategoryDto item,
|
||||
string langauge = null,
|
||||
string connectionId = null,
|
||||
@@ -108,6 +124,7 @@ namespace xCategoryService.Providers
|
||||
}
|
||||
|
||||
//
|
||||
var id = -1;
|
||||
try
|
||||
{
|
||||
//
|
||||
@@ -117,7 +134,7 @@ namespace xCategoryService.Providers
|
||||
//
|
||||
// Add Item Pure for ID Generating ...
|
||||
item = await base.Add(
|
||||
item: item,
|
||||
item: item,
|
||||
userInfo: userInfo,
|
||||
connectionId: null, // Since here We dont want notification ...
|
||||
cancellationToken: cancellationToken
|
||||
@@ -129,7 +146,7 @@ namespace xCategoryService.Providers
|
||||
}
|
||||
|
||||
//
|
||||
var id = item.Id;
|
||||
id = item.Id;
|
||||
var titleResourceTitle = await titleResourceProvider.AddOrUpdateItemResourcer(
|
||||
identifier: id,
|
||||
language: langauge,
|
||||
@@ -158,18 +175,59 @@ namespace xCategoryService.Providers
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var result = XCategoryTitleResourceProvider;
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Id ...
|
||||
isValid = id.IsValidIntId();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
throw new NotImplementedException();
|
||||
// Retrieve Category Resourv=ce ...
|
||||
var result = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveResaource(
|
||||
int id,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = id.IsValidIntId();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Resource ...
|
||||
var resource = await GetResource(
|
||||
id: id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
isValid = !resource.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
await titleResourceProvider.RemoveResource();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user