From ba74efaf3cdfd7675038b8cc680768a8be05d791 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 18 Dec 2025 15:59:35 +0330 Subject: [PATCH] last ... --- Controllers/XWebinarServiceControllerBase.cs | 104 +++++++- Interfaces/IXWebinarProvider.cs | 38 ++- .../IXWebinarServiceControllerActions.cs | 24 ++ Providers/XWebinarProvider.cs | 232 +++++++++++++++--- 4 files changed, 359 insertions(+), 39 deletions(-) diff --git a/Controllers/XWebinarServiceControllerBase.cs b/Controllers/XWebinarServiceControllerBase.cs index 83a81fb..b344218 100644 --- a/Controllers/XWebinarServiceControllerBase.cs +++ b/Controllers/XWebinarServiceControllerBase.cs @@ -86,7 +86,9 @@ namespace xWebinarService.Controllers // Preparing Tags List ... var tagList = new List(); if (!tags.IsNullOrEmpty()) { - tags.ParseListString(); + tagList = tags + .ParseListString() + .ToList(); } // @@ -431,6 +433,7 @@ namespace xWebinarService.Controllers var result = await WebinarProvider .Subscribe( webinarId: id, + userInfo: userInfo, subscriberId: subscriberId, connectionId: connectionId ); @@ -492,6 +495,7 @@ namespace xWebinarService.Controllers var result = await WebinarProvider .IsSubscribed( webinarId: id, + userInfo: userInfo, subscriberId: subscriberId ); @@ -554,6 +558,7 @@ namespace xWebinarService.Controllers var result = await WebinarProvider .Unsubscribe( webinarId: id, + userInfo: userInfo, subscriberId: subscriberId, connectionId: connectionId ); @@ -615,6 +620,7 @@ namespace xWebinarService.Controllers var result = await WebinarProvider .GetSubscriber( webinarId: id, + userInfo: userInfo, subscriberId: subscriberId ); @@ -671,7 +677,10 @@ namespace xWebinarService.Controllers // var result = await WebinarProvider - .GetSubscribers(id); + .GetSubscribers( + webinarId: id, + userInfo: userInfo + ); // return Ok(result. @@ -730,7 +739,8 @@ namespace xWebinarService.Controllers var result = await WebinarProvider .QuerySubscribers( query: query, - webinarId: id + webinarId: id, + userInfo: userInfo ); // @@ -846,9 +856,15 @@ namespace xWebinarService.Controllers // Do ... try { + // + var userInfo = await GetUserInfo(); + // var result = await WebinarProvider - .GetFiles(id); + .GetFiles( + id: id, + userInfo: userInfo + ); // return Ok(result. @@ -929,6 +945,86 @@ namespace xWebinarService.Controllers return result; } } + + /// + /// Attach Provided Files to Specified Webinar ... + /// + /// + /// + /// + [HttpGet("{id}/Files/AttachMany")] + public virtual async Task AttachFiles( + [FromRoute] Guid id, + [FromQuery] string ids + ) + { + // + // Do ... + try + { + // + var userInfo = await GetUserInfo(); + var connectionId = GetConnectionId(); + + // + await WebinarProvider + .AttachFiles( + id: id, + ids: ids, + userInfo: userInfo, + connectionId: connectionId + ); + + // + return Ok(); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Detach Provided Files to Specified Webinar ... + /// + /// + /// if null, detach all files ... + /// + [HttpGet("{id}/Files/DetachMany")] + public virtual async Task DetachFiles( + [FromRoute] Guid id, + [FromQuery] string ids = null + ) + { + // + // Do ... + try + { + // + var userInfo = await GetUserInfo(); + var connectionId = GetConnectionId(); + + // + await WebinarProvider + .DetachFiles( + id: id, + ids: ids, + userInfo: userInfo, + connectionId: connectionId + ); + + // + return Ok(); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } #endregion // diff --git a/Interfaces/IXWebinarProvider.cs b/Interfaces/IXWebinarProvider.cs index 6eed99f..b627d41 100644 --- a/Interfaces/IXWebinarProvider.cs +++ b/Interfaces/IXWebinarProvider.cs @@ -272,7 +272,7 @@ namespace xWebinarService.Interfaces Guid id, XUserClaimsInfoDto userInfo = null ); - + /// /// Stream Specified File ... /// @@ -281,8 +281,8 @@ namespace xWebinarService.Interfaces Task StreamFile( Guid id, Guid fileId - ); - + ); + /// /// Stream Specified File ... /// @@ -291,7 +291,37 @@ namespace xWebinarService.Interfaces Task DownloadFile( Guid id, Guid fileId - ); + ); + + /// + /// Attach Provided Files to Specified Webinar ... + /// + /// + /// + /// + /// + /// + Task AttachFiles( + Guid id, + string ids, + string connectionId = null, + XUserClaimsInfoDto userInfo = null + ); + + /// + /// Detach Provided Files to Specified Webinar ... + /// + /// + /// if null, detach all files ... + /// + /// + /// + Task DetachFiles( + Guid id, + string ids, + string connectionId = null, + XUserClaimsInfoDto userInfo = null + ); #endregion // diff --git a/Interfaces/IXWebinarServiceControllerActions.cs b/Interfaces/IXWebinarServiceControllerActions.cs index 3979671..0e3477b 100644 --- a/Interfaces/IXWebinarServiceControllerActions.cs +++ b/Interfaces/IXWebinarServiceControllerActions.cs @@ -213,6 +213,30 @@ namespace xWebinarService.Interfaces [FromRoute] Guid id, [FromRoute] Guid fileId ); + + /// + /// Attach Provided Files to Specified Webinar ... + /// + /// + /// + /// + [HttpGet("{id}/Files/AttachMany")] + Task AttachFiles( + [FromRoute] Guid id, + [FromQuery] string ids + ); + + /// + /// Detach Provided Files to Specified Webinar ... + /// + /// + /// if null, detach all files ... + /// + [HttpGet("{id}/Files/DetachMany")] + Task DetachFiles( + [FromRoute] Guid id, + [FromQuery] string ids = null + ); #endregion // diff --git a/Providers/XWebinarProvider.cs b/Providers/XWebinarProvider.cs index 3a4be9c..877ae26 100644 --- a/Providers/XWebinarProvider.cs +++ b/Providers/XWebinarProvider.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; -using IdentityModel.Client; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; @@ -309,7 +308,7 @@ namespace xWebinarService.Providers // // Check For Files ... - isValid = !files.IsNull(); + isValid = !files.IsNull() && files.Count() > 0; if (isValid) { // @@ -875,16 +874,36 @@ namespace xWebinarService.Providers // // Handle Remove ... var subscribers = await GetSubscribers( - webinarId: webinarId + webinarId: webinarId, + userInfo: userInfo ); try { // + // Unsubscribe all Subscribers ... await subscribers.SelectAsync(async s => await Unsubscribe( webinarId: webinarId, subscriberId: s.SubscriberId )); + // + // Detach Tags ... + await DetachTags( + id: entity.Id, + userInfo: userInfo, + connectionId: connectionId + ); + + // + // Detach Files ... + // + await DetachFiles( + ids: null, // Pass Null To Detach All Referenced Files ... + id: webinarId, + userInfo: userInfo, + connectionId: connectionId + ); + // string resourceID = webinarId.ToString(); await TitleResourceProvider.Remove(resourceID); @@ -895,33 +914,6 @@ namespace xWebinarService.Providers } catch { } - // - // Detach Tags ... - try - { - await DetachTags(entity.Id, userInfo); - } - catch { } - - // - // Remove Files ... - try - { - // - var medias = await WebinarFileProvider.GetAllReferences(entity.Id); - if (!medias.IsNull() && medias.HasChild()) - { - // - await RemoveFiles( - id: entity.Id, - ids: string.Empty, - userInfo: userInfo, - connectionId: connectionId - ); - } - } - catch { } - // // Check Entity Removed ... result = !await WebinarRepository.IsExistsAsync(webinarId); @@ -1629,7 +1621,185 @@ namespace xWebinarService.Providers // var result = await WebinarFileProvider.Download(fileId); return result; - } + } + + /// + /// Attach Provided Files to Specified Webinar ... + /// + /// + /// + /// + /// + /// + public async Task AttachFiles( + Guid id, + string ids, + string connectionId = null, + XUserClaimsInfoDto userInfo = null + ) + { + // + // Validate ... + var isValid = !id.IsNull() && + !id.IsDefaultGuid() && + !ids.IsNullOrEmpty() && + !userInfo.IsNullOrDefault(); + if (!isValid) + { + XException.InvalidArgs.Throw(); + } + + // + // Parse Files ... + var idsList = ids.ParseListGuid(); + isValid = !idsList.IsNull() && idsList.HasChild(); + if (!isValid) + { + XException.NotFound.Throw(); + } + + // + // Retrieve Webinar ... + var webinar = await WebinarRepository.GetAsync(id); + isValid = !webinar.IsNullOrDefault(); + if (!isValid) + { + XException.NotFound.Throw(); + } + + // + // Check Permissions ... + isValid = + userInfo.UserId == webinar.OwnerId || + userInfo.Roles.Any(r => r.ToNormalString() == "admin"); + if (!isValid) + { + XException.NotAllowed.Throw(); + } + + // + // Refrieve all Webinar Refrenced File ... + var references = await WebinarFileProvider.GetAllReferences(id); + if (!references.IsNull() && references.HasChild()) + { + // + // Filter ids which Exists in References ... + idsList = + idsList.Where(i => !references.Any(r => r.Id == i)); + } + + // + isValid = idsList.HasChild(); + if (!isValid) + { + return; + } + + // + foreach (var fileId in idsList) + { + // + // Check File Exists ... + var file = await WebinarFileProvider.FileProvider.Get(fileId); + isValid = !file.IsNullOrDefault(); + if (isValid) + { + // + await WebinarFileProvider.AddReference( + model: file, + providedForId: id, + forIndex: 0, + userInfo: userInfo, + connectionId: connectionId + ); + } + } + } + + /// + /// Detach Provided Files to Specified Webinar ... + /// + /// + /// if null, detach all files ... + /// + /// + /// + public async Task DetachFiles( + Guid id, + string ids, + string connectionId = null, + XUserClaimsInfoDto userInfo = null + ) + { + // + // Validate ... + var isValid = + !id.IsNull() && + !id.IsDefaultGuid() && + !userInfo.IsNullOrDefault(); + if (!isValid) + { + XException.InvalidArgs.Throw(); + } + + // + // Check Webinar Exists ... + var webinar = await WebinarRepository.GetAsync(id); + isValid = !webinar.IsNullOrDefault(); + if (!isValid) + { + XException.NotFound.Throw(); + } + + // + // Check Permissions ... + isValid = + userInfo.UserId == webinar.OwnerId || + userInfo.Roles.Any(r => r.ToNormalString() == "admin"); + if (!isValid) + { + XException.NotAllowed.Throw(); + } + + // + var references = await WebinarFileProvider.GetAllReferences(id); + isValid = !references.IsNull() && references.HasChild(); + if (!isValid) + { + return; + } + + // + // Parse IDS ... + if (!ids.IsNullOrEmpty()) + { + // + var idsList = ids.ParseListGuid(); + if (!idsList.IsNull() && idsList.HasChild()) + { + // + // Filtere References based on IDS ... + references = + references.Where(r => idsList.Contains(r.Id)); + } + } + + // + if (references.HasChild()) + { + // + foreach (var file in references) + { + // + await WebinarFileProvider.RemoveReference( + model: file, + providedForId: id, + userInfo: userInfo, + connectionId: connectionId + ); + } + } + } #endregion //