From d5498d9f6fdf6675bfd6b8bdb433a91004dfcb7b Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 19 Dec 2025 00:27:06 +0330 Subject: [PATCH] last works ... --- Controllers/XWebinarServiceControllerBase.cs | 25 +-- Interfaces/IXWebinarProvider.cs | 45 ++--- .../IXWebinarServiceControllerActions.cs | 5 +- Providers/XWebinarProvider.cs | 172 +++++++----------- 4 files changed, 96 insertions(+), 151 deletions(-) diff --git a/Controllers/XWebinarServiceControllerBase.cs b/Controllers/XWebinarServiceControllerBase.cs index bedf12a..a3ff8f3 100644 --- a/Controllers/XWebinarServiceControllerBase.cs +++ b/Controllers/XWebinarServiceControllerBase.cs @@ -15,6 +15,7 @@ using xWebinarService.Models.Dtos; using Microsoft.AspNetCore.Http; using XFileDto = xFileService.Models.Dtos.XFileDto; using xModels.Dtos; +using xTagService.Models.Dtos; namespace xWebinarService.Controllers { @@ -85,7 +86,8 @@ namespace xWebinarService.Controllers // // Preparing Tags List ... var tagList = new List(); - if (!tags.IsNullOrEmpty()) { + if (!tags.IsNullOrEmpty()) + { tagList = tags .ParseListString() .ToList(); @@ -901,8 +903,8 @@ namespace xWebinarService.Controllers // var result = GetExceptionActionResult(ex); return result; - } - } + } + } /// /// Attach Provided Files to Specified Webinar ... @@ -1009,12 +1011,12 @@ namespace xWebinarService.Controllers var connectionId = GetConnectionId(); // - var tagsList = tags.ParseListString(); await WebinarProvider .AttachTags( id: id, - tags: tagsList, + tags: tags, userInfo: userInfo, + forceAttachToFiles: true, connectionId: connectionId ); @@ -1033,7 +1035,7 @@ namespace xWebinarService.Controllers /// Detach Specified Tags From Specified Webinar ... /// /// - /// + /// if null, remove all attached tags ... /// [HttpDelete("{id}/Tags")] public virtual async Task DetachTags( @@ -1051,12 +1053,12 @@ namespace xWebinarService.Controllers var connectionId = GetConnectionId(); // - var tagsList = tags.ParseListString(); await WebinarProvider .DetachTags( id: id, - tags: tagsList, + tags: tags, userInfo: userInfo, + forceDetachFromFiles: true, connectionId: connectionId ); @@ -1077,7 +1079,7 @@ namespace xWebinarService.Controllers /// /// [HttpGet("{id}/Tags")] - public virtual async Task>> GetTags( + public virtual async Task>> GetTags( [FromRoute] Guid id ) { @@ -1090,14 +1092,15 @@ namespace xWebinarService.Controllers var userInfo = await GetUserInfo(); // - await WebinarProvider + var result = await WebinarProvider .GetTags( id: id, userInfo: userInfo ); // - return Ok(); + return Ok(result + .ToDynamicObject()); } catch (Exception ex) { diff --git a/Interfaces/IXWebinarProvider.cs b/Interfaces/IXWebinarProvider.cs index da952df..6f3085f 100644 --- a/Interfaces/IXWebinarProvider.cs +++ b/Interfaces/IXWebinarProvider.cs @@ -9,6 +9,7 @@ using xDataService.Configuration; using xIdentityModels.Models; using xIdentityService.Interfaces; using xModels.Dtos; +using xTagService.Models.Dtos; using xWebinarService.Hubs; using xWebinarService.Interfaces.Entities; using xWebinarService.Models.Dtos; @@ -314,17 +315,17 @@ namespace xWebinarService.Interfaces /// /// Attach Tag to Specified File ... /// - /// /// - /// + /// /// + /// /// /// Task AttachTag( - string tag, Guid id, - XUserClaimsInfoDto userInfo = null, + string tag, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceAttachToFiles = true ); @@ -338,58 +339,44 @@ namespace xWebinarService.Interfaces /// /// Task DetachTag( - string tag, Guid id, - XUserClaimsInfoDto userInfo = null, + string tag, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceDetachFromFiles = true ); /// /// Attach Tags for Specified File ... /// - /// /// - /// + /// /// + /// /// /// Task AttachTags( - IEnumerable tags, Guid id, - XUserClaimsInfoDto userInfo = null, + string tags, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceAttachToFiles = true ); /// /// Detach Tags for Specified File ... /// - /// /// + /// if nulls, detach all tags ... + /// /// - /// - /// - /// - Task DetachTags( - IEnumerable tags, - Guid id, - XUserClaimsInfoDto userInfo = null, - string connectionId = null, - bool forceDetachFromFiles = true - ); - - /// - /// Detach all Attached Tags for Specified File ... - /// - /// - /// /// /// Task DetachTags( Guid id, - XUserClaimsInfoDto userInfo = null, + string tags, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceDetachFromFiles = true ); @@ -399,7 +386,7 @@ namespace xWebinarService.Interfaces /// /// /// - Task> GetTags( + Task> GetTags( Guid id, XUserClaimsInfoDto userInfo = null ); diff --git a/Interfaces/IXWebinarServiceControllerActions.cs b/Interfaces/IXWebinarServiceControllerActions.cs index d1fe2ab..d76ad8b 100644 --- a/Interfaces/IXWebinarServiceControllerActions.cs +++ b/Interfaces/IXWebinarServiceControllerActions.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using xModels.Dtos; using XFileDto = xFileService.Models.Dtos.XFileDto; using xWebinarService.Models.Dtos; +using xTagService.Models.Dtos; namespace xWebinarService.Interfaces { @@ -245,7 +246,7 @@ namespace xWebinarService.Interfaces /// Detach Specified Tags From Specified Webinar ... /// /// - /// + /// if null, remove all attached tags ... /// Task DetachTags( [FromRoute] Guid id, @@ -257,7 +258,7 @@ namespace xWebinarService.Interfaces /// /// /// - Task>> GetTags( + Task>> GetTags( [FromRoute] Guid id ); #endregion diff --git a/Providers/XWebinarProvider.cs b/Providers/XWebinarProvider.cs index b697097..ea3cda3 100644 --- a/Providers/XWebinarProvider.cs +++ b/Providers/XWebinarProvider.cs @@ -17,6 +17,7 @@ using xIdentityService.Extensions; using xIdentityService.Interfaces; using xModels.Dtos; using xPushService.Constants; +using xTagService.Models.Dtos; using xWebinarService.Constants; using xWebinarService.Hubs; using xWebinarService.Interfaces; @@ -334,11 +335,11 @@ namespace xWebinarService.Providers { // await AttachTags( - tags: tags, id: entity.Id, userInfo: userInfo, - connectionId: connectionId, - true // + forceAttachToFiles: true, + tags: tags.ToListString(), + connectionId: connectionId ); } catch { } @@ -889,6 +890,7 @@ namespace xWebinarService.Providers // // Detach Tags ... await DetachTags( + tags: null, // Pass Null to Detach All Referenced Tags ... id: entity.Id, userInfo: userInfo, connectionId: connectionId @@ -1665,7 +1667,6 @@ namespace xWebinarService.Providers await WebinarFileProvider.AddReference( model: file, providedForId: id, - forIndex: 0, userInfo: userInfo, connectionId: connectionId ); @@ -1764,25 +1765,26 @@ namespace xWebinarService.Providers /// /// Attach Tag to Specified File ... /// - /// /// - /// + /// /// + /// /// /// public async Task AttachTag( - string tag, Guid id, - XUserClaimsInfoDto userInfo = null, + string tag, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceAttachToFiles = true ) { // // Validate ... - var isValid = !tag.IsNullOrEmpty() && + var isValid = !id.IsNull() && !id.IsDefaultGuid() && + !tag.IsNullOrEmpty() && !userInfo.IsNullOrDefault(); if (!isValid) { @@ -1807,7 +1809,6 @@ namespace xWebinarService.Providers // Attached Tag to Webinar ... await WebinarTagProvider.AddReference( tag: tag, - forIndex: 0, providedForId: id, connectionId: connectionId ); @@ -1840,25 +1841,27 @@ namespace xWebinarService.Providers /// /// Detach Tag fro Specified File ... /// - /// /// - /// + /// /// + /// /// /// public async Task DetachTag( - string tag, Guid id, - XUserClaimsInfoDto userInfo = null, + string tag, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceDetachFromFiles = true ) { // // Validate ... - var isValid = !tag.IsNullOrEmpty() && + var isValid = !id.IsNull() && - !id.IsDefaultGuid(); + !id.IsDefaultGuid() && + !tag.IsNullOrEmpty() && + !userInfo.IsNullOrDefault(); if (!isValid) { XException.InvalidArgs.Throw(); @@ -1914,26 +1917,27 @@ namespace xWebinarService.Providers /// /// Attach Tags for Specified File ... /// - /// /// - /// + /// /// + /// /// /// public async Task AttachTags( - IEnumerable tags, Guid id, - XUserClaimsInfoDto userInfo = null, + string tags, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceAttachToFiles = true ) { // // Validate ... - var isValid = !tags.IsNull() && - tags.HasChild() && + var isValid = !id.IsNull() && - !id.IsDefaultGuid(); + !id.IsDefaultGuid() && + !tags.IsNullOrEmpty() && + !userInfo.IsNullOrDefault(); if (!isValid) { XException.InvalidArgs.Throw(); @@ -1954,7 +1958,8 @@ namespace xWebinarService.Providers try { // - foreach (var tag in tags) + var tagsList = tags.ParseListString(); + foreach (var tag in tagsList) { // await AttachTag( @@ -1972,26 +1977,26 @@ namespace xWebinarService.Providers /// /// Detach Tags for Specified File ... /// - /// /// - /// + /// if null, Detach All ... /// + /// /// /// public async Task DetachTags( - IEnumerable tags, Guid id, - XUserClaimsInfoDto userInfo = null, + string tags, string connectionId = null, + XUserClaimsInfoDto userInfo = null, bool forceDetachFromFiles = true ) { // // Validate ... - var isValid = !tags.IsNull() && - tags.HasChild() && + var isValid = !id.IsNull() && - !id.IsDefaultGuid(); + !id.IsDefaultGuid() && + !userInfo.IsNullOrDefault(); if (!isValid) { XException.InvalidArgs.Throw(); @@ -2008,11 +2013,26 @@ namespace xWebinarService.Providers XException.NotAllowed.Throw(); } + // + IEnumerable tagsList; + if (!tags.IsNullOrEmpty()) + { + // + // Only Detach Provided Tags ... + tagsList = tags.ParseListString(); + } + else + { + // + // Select all Referenced Tags ... + tagsList = (await WebinarTagProvider.GetAllReferences(id)).Select(t => t.Tag); + } + // try { // - foreach (var tag in tags) + foreach (var tag in tagsList) { // await DetachTag( @@ -2027,79 +2047,13 @@ namespace xWebinarService.Providers catch { } } - /// - /// Detach all Attached Tags for Specified Webinar ... - /// - /// - /// - /// - /// - /// - public async Task DetachTags( - Guid id, - XUserClaimsInfoDto userInfo = null, - string connectionId = null, - bool forceDetachFromFiles = true - ) - { - // - // Validate ... - var isValid = !id.IsNull() && !id.IsDefaultGuid(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Permissions ... - isValid = await HasPermission( - id: id, - userInfo: userInfo - ); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - try - { - // - await WebinarTagProvider.RemoveReferences( - providedForId: id, - connectionId: connectionId - ); - - // - if (forceDetachFromFiles) - { - // - var medias = await WebinarFileProvider.GetAllReferences(id); - isValid = !medias.IsNull() && medias.HasChild(); - if (isValid) - { - // - foreach (var media in medias) - { - // - await WebinarFileProvider.FileProvider.TagProvider.RemoveReferences( - providedForId: media.Id, - connectionId: connectionId - ); - } - } - } - } - catch { } - } - /// /// Retrieve Specified Webinar's Tags ... /// /// /// /// - public async Task> GetTags( + public async Task> GetTags( Guid id, XUserClaimsInfoDto userInfo = null ) @@ -2140,18 +2094,18 @@ namespace xWebinarService.Providers // // Reading Tags Dto List ... - var tagsDtos = await WebinarTagProvider.GetAllReferences(id); + var result = await WebinarTagProvider.GetAllReferences(id); // - var result = new List(); - isValid = !tagsDtos.IsNull() && tagsDtos.HasChild(); - if (isValid) - { - // - result = tagsDtos - .Select(td => td.Tag) - .ToList(); - } + // var result = new List(); + // isValid = !tagsDtos.IsNull() && tagsDtos.HasChild(); + // if (isValid) + // { + // // + // result = tagsDtos + // .Select(td => td.Tag) + // .ToList(); + // } // return result;