From 496a9857526eefd1b8981c946d01c4d961d922e2 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 8 Dec 2025 18:15:37 +0330 Subject: [PATCH] last implementation of webinar provider which required to test, builds ok ... --- Interfaces/IXWebinarProvider.cs | 122 ++++++++++++++++++++++++++++++ Providers/XWebinarProvider.cs | 130 +++++++++++++++++++++++++++++++- 2 files changed, 250 insertions(+), 2 deletions(-) diff --git a/Interfaces/IXWebinarProvider.cs b/Interfaces/IXWebinarProvider.cs index 0647026..71801fa 100644 --- a/Interfaces/IXWebinarProvider.cs +++ b/Interfaces/IXWebinarProvider.cs @@ -1,14 +1,17 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; using xDataService.Configuration; +using xIdentityModels.Models; using xIdentityService.Interfaces; using xModels.Dtos; using xWebinarService.Hubs; using xWebinarService.Interfaces.Entities; using xWebinarService.Models.Dtos; using xWebinarService.Models.Entities; +using XFileDto = xFileService.Models.Dtos.XFileDto; namespace xWebinarService.Interfaces { @@ -51,10 +54,16 @@ namespace xWebinarService.Interfaces /// Create Webinar ... /// /// + /// + /// + /// /// /// Task CreateWebinar( XWebinarDto item, + IEnumerable tags = null, + IFormFileCollection files = null, + XUserClaimsInfoDto userInfo = null, string connectionId = null ); @@ -62,10 +71,12 @@ namespace xWebinarService.Interfaces /// Update a Webinar ... /// /// + /// /// /// Task UpdateWebinar( XWebinarDto item, + XUserClaimsInfoDto userInfo = null, string connectionId = null ); @@ -106,10 +117,12 @@ namespace xWebinarService.Interfaces /// Remove Specified Webinar ... /// /// + /// /// /// Task RemoveWebinar( Guid webinarId, + XUserClaimsInfoDto userInfo = null, string connectionId = null ); #endregion @@ -182,5 +195,114 @@ namespace xWebinarService.Interfaces XQuery query ); #endregion + + // + #region File Actions ... + /// + /// Upload Files ... + /// + /// + /// + /// + /// + Task> Upload( + Guid id, + IFormFileCollection files, + XUserClaimsInfoDto userInfo = null + ); + + /// + /// Remove Specified Files ... + /// + /// + /// + /// + /// + Task> RemoveFiles( + Guid id, + string ids = null, + XUserClaimsInfoDto userInfo = null + ); + + /// + /// Get Webinar Files ... + /// + /// + /// + Task> GetFiles(Guid id); + #endregion + + // + #region Tags Actions ... + /// + /// Attach Tag to Specified File ... + /// + /// + /// + /// + /// + /// + Task TagAttach( + string tag, + Guid id, + XUserClaimsInfoDto userInfo = null, + bool forceAttachToFiles = true + ); + + /// + /// Detach Tag fro Specified File ... + /// + /// + /// + /// + /// + /// + Task TagDetach( + string tag, + Guid id, + XUserClaimsInfoDto userInfo = null, + bool forceDetachFromFiles = true + ); + + /// + /// Attach Tags for Specified File ... + /// + /// + /// + /// + /// + /// + Task TagsAttach( + IEnumerable tags, + Guid id, + XUserClaimsInfoDto userInfo = null, + bool forceAttachToFiles = true + ); + + /// + /// Detach Tags for Specified File ... + /// + /// + /// + /// + /// + /// + Task TagsDetach( + IEnumerable tags, + Guid id, + XUserClaimsInfoDto userInfo = null, + bool forceDetachFromFiles = true + ); + + /// + /// Detach all Attached Tags for Specified File ... + /// + /// + /// + Task TagsDetach( + Guid id, + XUserClaimsInfoDto userInfo = null + ); + #endregion } } \ No newline at end of file diff --git a/Providers/XWebinarProvider.cs b/Providers/XWebinarProvider.cs index 7b8bc17..cad02da 100644 --- a/Providers/XWebinarProvider.cs +++ b/Providers/XWebinarProvider.cs @@ -178,10 +178,16 @@ namespace xWebinarService.Providers /// Create Webinar ... /// /// + /// + /// + /// /// /// public async Task CreateWebinar( XWebinarDto item, + IEnumerable tags = null, + IFormFileCollection files = null, + XUserClaimsInfoDto userInfo = null, string connectionId = null ) { @@ -191,7 +197,9 @@ namespace xWebinarService.Providers !item.IsNull() && !item.Title.IsNull() && !item.Description.IsNull() && - !item.OwnerId.IsNullOrEmpty(); + !userInfo.IsNullOrDefault() && + !item.OwnerId.IsNullOrEmpty() && + userInfo.UserId == item.OwnerId; if (!isValid) { XException.InvalidArgs.Throw(); @@ -295,6 +303,43 @@ namespace xWebinarService.Providers XException.ActionFailed.Throw(); } + // + // Check For Files ... + isValid = !files.IsNull(); + if (isValid) + { + // + try + { + // + await Upload( + id: entity.Id, + files: files, + userInfo: userInfo + ); + } + catch { } + } + + // + // Check For Tags ... + isValid = !tags.IsNull() && tags.HasChild(); + if (isValid) + { + // + try + { + // + await TagsAttach( + tags: tags, + id: entity.Id, + userInfo: userInfo, + true // + ); + } + catch { } + } + // await SendPush( action: XBaseEntityHubAction.Add.GetStringValue(), @@ -312,10 +357,12 @@ namespace xWebinarService.Providers /// Update a Webinar ... /// /// + /// /// /// public async Task UpdateWebinar( XWebinarDto item, + XUserClaimsInfoDto userInfo = null, string connectionId = null ) { @@ -323,9 +370,9 @@ namespace xWebinarService.Providers // Validate ... bool isValid = !item.Id.IsNull() && - !item.IsNullOrDefault() && !item.Id.IsDefaultGuid() && + !userInfo.IsNullOrDefault() && !item.OwnerId.IsNullOrEmpty() && !item.Title.IsNullOrDefault() && !item.Description.IsNullOrDefault() && @@ -345,6 +392,14 @@ namespace xWebinarService.Providers XException.InvalidArgs.Throw(); } + // + // Check Permissions ... + isValid = await HasPermission(item.Id, userInfo); + if (!isValid) + { + XException.NotAllowed.Throw(); + } + // // Check Item Exists ... isValid = await WebinarRepository.IsExistsAsync(item.Id); @@ -679,10 +734,12 @@ namespace xWebinarService.Providers /// Remove Specified Webinar ... /// /// + /// /// /// public async Task RemoveWebinar( Guid webinarId, + XUserClaimsInfoDto userInfo = null, string connectionId = null ) { @@ -699,6 +756,14 @@ namespace xWebinarService.Providers return result; } + // + // Check Permissions ... + result = await HasPermission(webinarId, userInfo); + if (!result) + { + XException.NotAllowed.Throw(); + } + // // Get Entity ... var entity = await WebinarRepository.GetAsync(webinarId); @@ -731,6 +796,27 @@ namespace xWebinarService.Providers } catch { } + // + // Detach Tags ... + try + { + await TagsDetach(entity.Id, userInfo); + } + catch { } + + // + // Remove Files ... + try + { + // + var medias = await WebinarFileProvider.GetAllFor(entity.Id); + if (!medias.IsNull() && medias.HasChild()) + { + await RemoveFiles(entity.Id, string.Empty, userInfo); + } + } + catch { } + // // Check Entity Removed ... result = !await WebinarRepository.IsExistsAsync(webinarId); @@ -1203,6 +1289,46 @@ namespace xWebinarService.Providers return result; } + /// + /// Remove Specified Files ... + /// + /// + /// + /// + /// + public async Task> RemoveFiles( + Guid id, + string ids = null, + XUserClaimsInfoDto userInfo = null + ) + { + // + // Validate ... + var isValid = !id.IsNull() && + !id.IsDefaultGuid() && + !userInfo.IsNullOrDefault(); + if (!isValid) + { + XException.InvalidArgs.Throw(); + } + + // + // Check Permission ... + isValid = await HasPermission(id, userInfo); + if (!isValid) + { + XException.NotAllowed.Throw(); + } + + // + var result = await WebinarFileProvider.Remove( + id, + ids, + userInfo + ); + return result; + } + /// /// Get Webinar Files ... ///