From d2d3ac90b63a2b85ba304f687b0e8f3d574defd0 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 24 Jul 2026 19:46:35 +0330 Subject: [PATCH] implement Webinar and WebinarSubscriber Entity and Dto (s) and Data Requirements ... --- .../Entities/XWebinarEntityConfiguration.cs | 16 + .../XWebinarSubscriberEntityConfiguration.cs | 15 + {Helpers => Constants}/.gitkeep | 0 Constants/XWebinarHubAction.cs | 51 - ...narServiceConstants.cs => XWebinarType.cs} | 5 +- {Models => Controllers}/.gitkeep | 0 Controllers/XWebinarServiceControllerBase.cs | 1114 --------- DI/XDIHelperExtension.cs | 226 +- DataHelper/Events/XWebinarEvents.cs | 9 - DataHelper/Events/XWebinarSubscriberEvents.cs | 9 - {Providers => Extensions}/.gitkeep | 0 Extensions/xWebinarServiceExtensions.cs | 3 - Helpers/XWebinarServiceHelper.cs | 550 ++++ Hubs/XWebinarEntityHub.cs | 16 - Hubs/XWebinarHub.cs | 562 ----- Interfaces/Dtos/IXWebinarDtoHub.cs | 10 + Interfaces/Dtos/IXWebinarRepositoryService.cs | 10 + Interfaces/Dtos/IXWebinarServiceProvider.cs | 14 + Interfaces/Dtos/IXWebinarSubscriberDtoHub.cs | 9 + .../IXWebinarSubscriberRepositoryService.cs | 9 + .../IXWebinarSubscriberServiceProvider.cs | 12 + Interfaces/Entities/IXWebinarEntityHub.cs | 9 + ...iberEvents.cs => IXWebinarKeyGenerator.cs} | 3 +- ...Events.cs => IXWebinarRepositoryEvents.cs} | 2 +- .../Entities/IXWebinarRepositoryProvider.cs | 10 + .../Entities/IXWebinarSubscriberEntityHub.cs | 8 + .../IXWebinarSubscriberKeyGenerator.cs | 8 + .../IXWebinarSubscriberRepositoryEvents.cs | 8 + .../IXWebinarSubscriberRepositoryProvider.cs | 9 + .../IXWebinarDescriptionResourceProvider.cs | 7 - Interfaces/IXWebinarFileProvider.cs | 8 - Interfaces/IXWebinarProvider.cs | 395 --- ...ebinarGroupStore.cs => IXWebinarSeeder.cs} | 6 +- .../IXWebinarServiceControllerActions.cs | 266 -- Interfaces/IXWebinarSubscriberSeeder.cs | 8 + Interfaces/IXWebinarTagProvider.cs | 8 - Interfaces/IXWebinarTitleResourceProvider.cs | 7 - Models/Dtos/XWebinarDto.cs | 18 +- Models/Dtos/XWebinarSubscriberDto.cs | 14 + Models/Entities/XWebinar.cs | 14 +- Models/Entities/XWebinarGroupEntity.cs | 13 - Models/Entities/XWebinarSubscriber.cs | 20 + Providers/Dtos/XWebinarDtoHub.cs | 17 + Providers/Dtos/XWebinarRepositoryService.cs | 23 + Providers/Dtos/XWebinarServiceProvider.cs | 27 + Providers/Dtos/XWebinarSubscriberDtoHub.cs | 16 + .../XWebinarSubscriberRepositoryService.cs | 22 + .../Dtos/XWebinarSubscriberServiceProvider.cs | 26 + Providers/Entities/XWebinarEFRepository.cs | 27 + Providers/Entities/XWebinarEntityHub.cs | 16 + .../Entities/XWebinarInMemoryRepository.cs | 22 + Providers/Entities/XWebinarKeyGenerator.cs | 9 + Providers/Entities/XWebinarMongoRepository.cs | 26 + .../Entities/XWebinarRepositoryEvents.cs | 9 + .../Entities/XWebinarRepositoryProvider.cs | 26 + .../XWebinarSubscriberEFRepository.cs | 26 + .../Entities/XWebinarSubscriberEntityHub.cs | 15 + .../XWebinarSubscriberInMemoryRepository.cs | 21 + .../XWebinarSubscriberKeyGenerator.cs | 9 + .../XWebinarSubscriberMongoRepository.cs | 25 + .../XWebinarSubscriberRepositoryEvents.cs | 9 + .../XWebinarSubscriberRepositoryProvider.cs | 26 + .../GraphQL/XWebinarGraphQLTypeHelper.cs | 2 +- .../GraphQL/XWebinarGraphQuery.cs | 2 +- .../GraphQL/XWebinarGraphSchema.cs | 2 +- .../GraphQL/XWebinarGraphType.cs | 6 +- .../XWebinarSubscriberGraphQLTypeHelper.cs | 10 +- .../GraphQL/XWebinarSubscriberGraphQuery.cs | 5 +- .../GraphQL/XWebinarSubscriberGraphSchema.cs | 2 +- .../GraphQL/XWebinarSubscriberGraphType.cs | 4 +- .../XWebinarDescriptionResourceProvider.cs | 23 - Providers/XWebinarEntityRegisterar.cs | 35 + Providers/XWebinarFileProvider.cs | 19 - Providers/XWebinarGroupStore.cs | 20 - Providers/XWebinarProvider.cs | 2214 ----------------- Providers/XWebinarSeederBase.cs | 25 + .../XWebinarSubscriberEntityRegisterar.cs | 34 + Providers/XWebinarSubscriberSeederBase.cs | 25 + Providers/XWebinarTagProvider.cs | 19 - Providers/XWebinarTitleResourceProvider.cs | 23 - nuget.config | 3 +- xWebinarService.csproj | 4 +- 82 files changed, 1466 insertions(+), 4889 deletions(-) create mode 100644 Configurations/Entities/XWebinarEntityConfiguration.cs create mode 100644 Configurations/Entities/XWebinarSubscriberEntityConfiguration.cs rename {Helpers => Constants}/.gitkeep (100%) delete mode 100644 Constants/XWebinarHubAction.cs rename Constants/{xWebinarServiceConstants.cs => XWebinarType.cs} (73%) rename {Models => Controllers}/.gitkeep (100%) delete mode 100644 Controllers/XWebinarServiceControllerBase.cs delete mode 100644 DataHelper/Events/XWebinarEvents.cs delete mode 100644 DataHelper/Events/XWebinarSubscriberEvents.cs rename {Providers => Extensions}/.gitkeep (100%) delete mode 100644 Extensions/xWebinarServiceExtensions.cs create mode 100644 Helpers/XWebinarServiceHelper.cs delete mode 100644 Hubs/XWebinarEntityHub.cs delete mode 100644 Hubs/XWebinarHub.cs create mode 100644 Interfaces/Dtos/IXWebinarDtoHub.cs create mode 100644 Interfaces/Dtos/IXWebinarRepositoryService.cs create mode 100644 Interfaces/Dtos/IXWebinarServiceProvider.cs create mode 100644 Interfaces/Dtos/IXWebinarSubscriberDtoHub.cs create mode 100644 Interfaces/Dtos/IXWebinarSubscriberRepositoryService.cs create mode 100644 Interfaces/Dtos/IXWebinarSubscriberServiceProvider.cs create mode 100644 Interfaces/Entities/IXWebinarEntityHub.cs rename Interfaces/Entities/{IXWebinarSubscriberEvents.cs => IXWebinarKeyGenerator.cs} (58%) rename Interfaces/Entities/{IXWebinarEvents.cs => IXWebinarRepositoryEvents.cs} (60%) create mode 100644 Interfaces/Entities/IXWebinarRepositoryProvider.cs create mode 100644 Interfaces/Entities/IXWebinarSubscriberEntityHub.cs create mode 100644 Interfaces/Entities/IXWebinarSubscriberKeyGenerator.cs create mode 100644 Interfaces/Entities/IXWebinarSubscriberRepositoryEvents.cs create mode 100644 Interfaces/Entities/IXWebinarSubscriberRepositoryProvider.cs delete mode 100644 Interfaces/IXWebinarDescriptionResourceProvider.cs delete mode 100644 Interfaces/IXWebinarFileProvider.cs delete mode 100644 Interfaces/IXWebinarProvider.cs rename Interfaces/{IXWebinarGroupStore.cs => IXWebinarSeeder.cs} (53%) delete mode 100644 Interfaces/IXWebinarServiceControllerActions.cs create mode 100644 Interfaces/IXWebinarSubscriberSeeder.cs delete mode 100644 Interfaces/IXWebinarTagProvider.cs delete mode 100644 Interfaces/IXWebinarTitleResourceProvider.cs create mode 100644 Models/Dtos/XWebinarSubscriberDto.cs delete mode 100644 Models/Entities/XWebinarGroupEntity.cs create mode 100644 Models/Entities/XWebinarSubscriber.cs create mode 100644 Providers/Dtos/XWebinarDtoHub.cs create mode 100644 Providers/Dtos/XWebinarRepositoryService.cs create mode 100644 Providers/Dtos/XWebinarServiceProvider.cs create mode 100644 Providers/Dtos/XWebinarSubscriberDtoHub.cs create mode 100644 Providers/Dtos/XWebinarSubscriberRepositoryService.cs create mode 100644 Providers/Dtos/XWebinarSubscriberServiceProvider.cs create mode 100644 Providers/Entities/XWebinarEFRepository.cs create mode 100644 Providers/Entities/XWebinarEntityHub.cs create mode 100644 Providers/Entities/XWebinarInMemoryRepository.cs create mode 100644 Providers/Entities/XWebinarKeyGenerator.cs create mode 100644 Providers/Entities/XWebinarMongoRepository.cs create mode 100644 Providers/Entities/XWebinarRepositoryEvents.cs create mode 100644 Providers/Entities/XWebinarRepositoryProvider.cs create mode 100644 Providers/Entities/XWebinarSubscriberEFRepository.cs create mode 100644 Providers/Entities/XWebinarSubscriberEntityHub.cs create mode 100644 Providers/Entities/XWebinarSubscriberInMemoryRepository.cs create mode 100644 Providers/Entities/XWebinarSubscriberKeyGenerator.cs create mode 100644 Providers/Entities/XWebinarSubscriberMongoRepository.cs create mode 100644 Providers/Entities/XWebinarSubscriberRepositoryEvents.cs create mode 100644 Providers/Entities/XWebinarSubscriberRepositoryProvider.cs rename {DataHelper => Providers}/GraphQL/XWebinarGraphQLTypeHelper.cs (93%) rename {DataHelper => Providers}/GraphQL/XWebinarGraphQuery.cs (92%) rename {DataHelper => Providers}/GraphQL/XWebinarGraphSchema.cs (86%) rename {DataHelper => Providers}/GraphQL/XWebinarGraphType.cs (77%) rename {DataHelper => Providers}/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs (79%) rename {DataHelper => Providers}/GraphQL/XWebinarSubscriberGraphQuery.cs (90%) rename {DataHelper => Providers}/GraphQL/XWebinarSubscriberGraphSchema.cs (87%) rename {DataHelper => Providers}/GraphQL/XWebinarSubscriberGraphType.cs (89%) delete mode 100644 Providers/XWebinarDescriptionResourceProvider.cs create mode 100644 Providers/XWebinarEntityRegisterar.cs delete mode 100644 Providers/XWebinarFileProvider.cs delete mode 100644 Providers/XWebinarGroupStore.cs delete mode 100644 Providers/XWebinarProvider.cs create mode 100644 Providers/XWebinarSeederBase.cs create mode 100644 Providers/XWebinarSubscriberEntityRegisterar.cs create mode 100644 Providers/XWebinarSubscriberSeederBase.cs delete mode 100644 Providers/XWebinarTagProvider.cs delete mode 100644 Providers/XWebinarTitleResourceProvider.cs diff --git a/Configurations/Entities/XWebinarEntityConfiguration.cs b/Configurations/Entities/XWebinarEntityConfiguration.cs new file mode 100644 index 0000000..18c9a63 --- /dev/null +++ b/Configurations/Entities/XWebinarEntityConfiguration.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using xDataService.Providers; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Configurations.Entities +{ + public class XWebinarEntityConfiguration : XBaseEntityTypeConfiguration + { + public override void Configure(EntityTypeBuilder builder) + { + builder.ToTable("Webinars"); + } + } +} \ No newline at end of file diff --git a/Configurations/Entities/XWebinarSubscriberEntityConfiguration.cs b/Configurations/Entities/XWebinarSubscriberEntityConfiguration.cs new file mode 100644 index 0000000..3d0496f --- /dev/null +++ b/Configurations/Entities/XWebinarSubscriberEntityConfiguration.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using xDataService.Providers; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Configurations.Entities +{ + public class XWebinarSubscriberEntityConfiguration : XBaseEntityTypeConfiguration + { + public override void Configure(EntityTypeBuilder builder) + { + builder.ToTable("WebinarSubscribers"); + } + } +} \ No newline at end of file diff --git a/Helpers/.gitkeep b/Constants/.gitkeep similarity index 100% rename from Helpers/.gitkeep rename to Constants/.gitkeep diff --git a/Constants/XWebinarHubAction.cs b/Constants/XWebinarHubAction.cs deleted file mode 100644 index e84f80b..0000000 --- a/Constants/XWebinarHubAction.cs +++ /dev/null @@ -1,51 +0,0 @@ -using xExceptions.Attributes; - -namespace xWebinarService.Constants -{ - /// - /// Webinar Connection Hub Actions ... - /// - public enum XWebinarHubAction - { - /// - /// When a Webinar is Available to Join ... - /// - [StringValue("WebinarOpened")] - WebinarOpened, - - /// - /// When a Webinar Closed ... - /// - [StringValue("WebinarClosed")] - WebinarClosed, - - /// - /// When a Viewer is Joined to Webinar ... - /// - [StringValue("ViewerJoined")] - ViewerJoined, - - /// - /// When a Webinar Subscriber Leaved a Webinar ... - /// - [StringValue("ViewerLeaved")] - ViewerLeaved, - - /// - /// Send a Message to Webinar ... - /// - [StringValue("Message")] - Message, - } - - /// - /// Entity Hub Actions ... - /// - public enum XWebinarEntityHubAction - { - [StringValue("Subscribe")] - Subscribe, - [StringValue("Unsubscribe")] - Unsubscribe - } -} \ No newline at end of file diff --git a/Constants/xWebinarServiceConstants.cs b/Constants/XWebinarType.cs similarity index 73% rename from Constants/xWebinarServiceConstants.cs rename to Constants/XWebinarType.cs index 2b727fc..277e249 100644 --- a/Constants/xWebinarServiceConstants.cs +++ b/Constants/XWebinarType.cs @@ -1,8 +1,7 @@ using xExceptions.Attributes; -namespace xWebinarService.Constants { - public class xWebinarServiceConstants { } - +namespace xWebinarService.Constants +{ /// /// Webinar Type ... /// diff --git a/Models/.gitkeep b/Controllers/.gitkeep similarity index 100% rename from Models/.gitkeep rename to Controllers/.gitkeep diff --git a/Controllers/XWebinarServiceControllerBase.cs b/Controllers/XWebinarServiceControllerBase.cs deleted file mode 100644 index a3ff8f3..0000000 --- a/Controllers/XWebinarServiceControllerBase.cs +++ /dev/null @@ -1,1114 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using xCommons.Configurations; -using xCommons.Extensions; -using xCommons.Providers; -using xExceptions.Constants; -using xIdentityService.Controllers; -using xIdentityService.Interfaces; -using xWebinarService.Interfaces; -using xWebinarService.Models.Dtos; -using Microsoft.AspNetCore.Http; -using XFileDto = xFileService.Models.Dtos.XFileDto; -using xModels.Dtos; -using xTagService.Models.Dtos; - -namespace xWebinarService.Controllers -{ - /// - /// a Controller base Class which implement based Actions to Provides Webinar Provider Access ... - /// - public abstract class XWebinarServiceControllerBase : XIBaseProviderController, IXWebinarServiceControllerActions - { - // - #region Props ... - public IXWebinarProvider WebinarProvider { get; } - #endregion - - // - #region Constructor ... - public XWebinarServiceControllerBase( - ILogger logger, - IXWebinarProvider webinarProvider, - XAppConfiguration appConfiguration, - IXIdentityProvider identityProvider, - XValidationProvider validationProvider - ) : base( - logger, - appConfiguration, - identityProvider, - validationProvider - ) - { - // - WebinarProvider = webinarProvider; - } - #endregion - - // - #region Actions ... - /// - /// Create Webinar ... - /// - /// - /// - /// - /// - [HttpPost("")] - public virtual async Task> CreateWebinar( - [FromForm] XWebinarDto item, - [FromQuery] string tags = null, - [FromForm] IFormFileCollection files = null - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Check Owner ... - if (item.OwnerId.IsNullOrEmpty()) - { - item.OwnerId = userId; - } - - // - // Preparing Tags List ... - var tagList = new List(); - if (!tags.IsNullOrEmpty()) - { - tagList = tags - .ParseListString() - .ToList(); - } - - // - var result = await WebinarProvider - .CreateWebinar( - item: item, - files: files, - tags: tagList, - userInfo: userInfo, - connectionId: connectionId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Update a Webinar ... - /// - /// - /// - /// - [HttpPut("{id}")] - public virtual async Task> UpdateWebinar( - [FromRoute] Guid id, - [FromBody] XWebinarDto item - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Check Permission ... - bool has = item.OwnerId == userId || isAdmin; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .UpdateWebinar( - item: item, - userInfo: userInfo, - connectionId: connectionId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Retrieve Specified Webinar ... - /// - /// - /// - [HttpGet("{id}")] - public virtual async Task> GetWebinar( - [FromRoute] Guid id - ) - { - // - // Do ... - try - { - // - var result = await WebinarProvider - .GetWebinar(id); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Retrieve all Exists Webinars ... - /// - /// - [HttpGet("All")] - public virtual async Task>> GetWebinars() - { - // - // Do ... - try - { - // - var result = await WebinarProvider - .GetWebinars(); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Query Webinars ... - /// - /// - /// - [HttpGet("Query")] - public virtual async Task>> QueryWebinars( - [FromQuery] XQuery query - ) - { - // - // Do ... - try - { - // - var result = await WebinarProvider - .QueryWebinars(query); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Query Owned Webinars ... - /// - /// - /// - [HttpGet("Query/Owned")] - public virtual async Task>> QueryOwnedWebinars( - [FromQuery] XQuery query - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - - // - var result = await WebinarProvider - .QueryOwnedWebinars( - query: query, - userInfo: userInfo - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Query Joinable Webinars ... - /// - /// - /// - [HttpGet("Query/Joinable")] - public virtual async Task>> QueryJoinableWebinars( - [FromQuery] XQuery query - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - - // - var result = await WebinarProvider - .QueryJoinableWebinars( - query: query, - userInfo: userInfo - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Remove Specified Webinar ... - /// - /// - /// - [HttpDelete("{id}")] - public virtual async Task> RemoveWebinar( - [FromRoute] Guid id - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = entity.OwnerId == userId || isAdmin; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .RemoveWebinar( - webinarId: id, - userInfo: userInfo, - connectionId: connectionId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - #endregion - - // - #region WebinarSubscriber ... - /// - /// Subscribe a User to Webinar ... - /// - /// - /// - /// - [HttpPost("{id}/Subscribe/{subscriberId}")] - public virtual async Task> Subscribe( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = - isAdmin || - entity.OwnerId == userId || - entity.Type == Constants.XWebinarType.Public; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .Subscribe( - webinarId: id, - userInfo: userInfo, - subscriberId: subscriberId, - connectionId: connectionId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Check Specified User Subscribed on a Webinar or not ... - /// - /// - /// - /// - [HttpGet("{id}/IsSubscribed/{subscriberId}")] - public virtual async Task> IsSubscribed( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = - isAdmin || - entity.OwnerId == userId; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .IsSubscribed( - webinarId: id, - userInfo: userInfo, - subscriberId: subscriberId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Unsubscribe Specified User from a Specified Webinar ... - /// - /// - /// - /// - [HttpDelete("{id}/Unsubscribe/{subscriberId}")] - public virtual async Task> Unsubscribe( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = - isAdmin || - subscriberId == userId || - entity.OwnerId == userId; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .Unsubscribe( - webinarId: id, - userInfo: userInfo, - subscriberId: subscriberId, - connectionId: connectionId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Retrieve Specified Subscriber ... - /// - /// - /// - /// - [HttpGet("{id}/Subscriber/{subscriberId}")] - public virtual async Task> GetSubscriber( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = - isAdmin || - entity.OwnerId == userId; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .GetSubscriber( - webinarId: id, - userInfo: userInfo, - subscriberId: subscriberId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Get all Specified Webinars Subscribers ... - /// - /// - /// - [HttpGet("{id}/Subscribers")] - public virtual async Task>> GetSubscribers( - [FromRoute] Guid id - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = - isAdmin || - entity.OwnerId == userId; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .GetSubscribers( - webinarId: id, - userInfo: userInfo - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Query Specified Webinar's Subscribers ... - /// - /// - /// - /// - [HttpGet("{id}/Subscribers/Query")] - public virtual async Task>> QuerySubscribers( - [FromRoute] Guid id, - [FromQuery] XQuery query - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - var userId = userInfo.UserId; - - // - // Retrieve Entity ... - var entity = await WebinarProvider.GetWebinar(id); - bool has = !entity.IsNullOrDefault(); - if (!has) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - has = - isAdmin || - entity.OwnerId == userId; - if (!has) - { - XException.NotAllowed.Throw(); - } - - // - var result = await WebinarProvider - .QuerySubscribers( - query: query, - webinarId: id, - userInfo: userInfo - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - #endregion - - // - #region File Actions ... - /// - /// Upload Specified Files for Specified Webinar ... - /// - /// - /// - /// - [HttpPost("{id}/Files")] - public virtual async Task>> UploadFiles( - [FromRoute] Guid id, - [FromForm] IFormFileCollection files - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - - // - var result = await WebinarProvider - .UploadFiles( - id: id, - files: files, - userInfo: userInfo, - connectionId: connectionId - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Retrieve Specified Webinar's Files ... - /// - /// - /// - [HttpGet("{id}/Files")] - public virtual async Task>> GetFiles( - [FromRoute] Guid id - ) - { - // - // Do ... - try - { - // - var userInfo = await GetUserInfo(); - - // - var result = await WebinarProvider - .GetFiles( - id: id, - userInfo: userInfo - ); - - // - return Ok(result. - ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Stream Specified File of Specified Webinar ... - /// - /// - /// - /// - [HttpGet("{id}/Files/{fileId}/Stream")] - public virtual async Task StreamFile( - [FromRoute] Guid id, - [FromRoute] Guid fileId - ) - { - // - // Do ... - try - { - // - var result = await WebinarProvider - .StreamFile( - id: id, - fileId: fileId - ); - - // - return result; - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Download Specified File of Specified Webinar ... - /// - /// - /// - /// - [HttpGet("{id}/Files/{fileId}/Download")] - public virtual async Task DownloadFile( - [FromRoute] Guid id, - [FromRoute] Guid fileId - ) - { - // - // Do ... - try - { - // - var result = await WebinarProvider - .DownloadFile( - id: id, - fileId: fileId - ); - - // - return result; - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Attach Provided Files to Specified Webinar ... - /// - /// - /// - /// - [HttpPost("{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 ... - /// - [HttpDelete("{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 - - // - #region Tags Actions ... - /// - /// Attach Specified Tags To Specified Webinar ... - /// - /// - /// - /// - [HttpPost("{id}/Tags")] - public virtual async Task AttachTags( - [FromRoute] Guid id, - [FromQuery] string tags - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - - // - await WebinarProvider - .AttachTags( - id: id, - tags: tags, - userInfo: userInfo, - forceAttachToFiles: true, - connectionId: connectionId - ); - - // - return Ok(); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Detach Specified Tags From Specified Webinar ... - /// - /// - /// if null, remove all attached tags ... - /// - [HttpDelete("{id}/Tags")] - public virtual async Task DetachTags( - [FromRoute] Guid id, - [FromQuery] string tags - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - var connectionId = GetConnectionId(); - - // - await WebinarProvider - .DetachTags( - id: id, - tags: tags, - userInfo: userInfo, - forceDetachFromFiles: true, - connectionId: connectionId - ); - - // - return Ok(); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - - /// - /// Retrieve Specified Webinars Tags ... - /// - /// - /// - [HttpGet("{id}/Tags")] - public virtual async Task>> GetTags( - [FromRoute] Guid id - ) - { - // - // Do ... - try - { - // - // Retrieve User Info ... - var userInfo = await GetUserInfo(); - - // - var result = await WebinarProvider - .GetTags( - id: id, - userInfo: userInfo - ); - - // - return Ok(result - .ToDynamicObject()); - } - catch (Exception ex) - { - // - var result = GetExceptionActionResult(ex); - return result; - } - } - #endregion - } -} \ No newline at end of file diff --git a/DI/XDIHelperExtension.cs b/DI/XDIHelperExtension.cs index 7d8082d..7360012 100644 --- a/DI/XDIHelperExtension.cs +++ b/DI/XDIHelperExtension.cs @@ -1,15 +1,20 @@ using System; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using xCommons.Extensions; -using xDataService.Interfaces; -using xDataService.Providers; +using xCommons.Helpers; +using xDataService.Constants; +using xDataService.Db; +using xDataService.DI; +using xDataService.Models; using xExceptions.Constants; -using xFileService.Interfaces; -using xTagService.Interfaces; -using xWebinarService.Interfaces; +using xPushService.DI; +using xPushService.Helpers; +using xWebinarService.Helpers; +using xWebinarService.Interfaces.Dtos; using xWebinarService.Interfaces.Entities; -using xWebinarService.Models.Entities; -using xWebinarService.Providers; +using xWebinarService.Providers.Dtos; +using xWebinarService.Providers.Entities; namespace xWebinarService.DI { @@ -19,21 +24,99 @@ namespace xWebinarService.DI /// Register Service ... /// /// - /// + /// + /// public static void AddXWebinarService( this IServiceCollection services, - ServiceLifetime lifeTime + XRepositoryType repositoryType, + ServiceLifetime lifeTime = ServiceLifetime.Scoped + ) + { + AddWebinarService( + contextType: null, + services: services, + lifeTime: lifeTime, + repositoryType: repositoryType + ); + } + + /// + /// Register Service ... + /// + /// + /// + /// + /// + public static void AddXWebinarService( + this IServiceCollection services, + XRepositoryType repositoryType, + ServiceLifetime lifeTime = ServiceLifetime.Scoped + ) + where TContext : XDbContext + { + AddWebinarService( + services: services, + lifeTime: lifeTime, + contextType: typeof(TContext), + repositoryType: repositoryType + ); + } + + /// + /// Use XWebinarService Middleware ... + /// + /// + /// + public static void UsexWebinarService( + this IApplicationBuilder app, + bool isDevelopmentEnvironment = false ) { // - AddWebinarService( - services, - lifeTime - ); + #region Using XWebinar Hubs ... + // + var pushHelper = new XPushServiceHelper(); + + // + pushHelper.AddHub("webinarDto"); + pushHelper.AddHub("webinarEntity"); + + // + pushHelper.AddHub("webinarSubscriberDto"); + pushHelper.AddHub("webinarSubscriberEntity"); + + // + app.UseXPushService(pushHelper); + #endregion + + // + // Using XWebinar Repository Descriptor ... + if (!webinarDescriptor.IsNull()) + { + // + app.UseXRepository( + descriptor: webinarDescriptor, + isDevelopmentEnvironment: isDevelopmentEnvironment + ); + } + + // + // Using XWebinarSubscriber Repository Descriptor ... + if (!webinarSubscriberDescriptor.IsNull()) + { + // + app.UseXRepository( + descriptor: webinarSubscriberDescriptor, + isDevelopmentEnvironment: isDevelopmentEnvironment + ); + } } // #region Private ... + private static XRepositoryDescriptor webinarDescriptor = null; + private static XRepositoryDescriptor webinarSubscriberDescriptor = null; + /// /// a LogTag for Service ... /// @@ -52,10 +135,14 @@ namespace xWebinarService.DI /// Register Service ... /// /// + /// + /// /// private static void AddWebinarService( IServiceCollection services, - ServiceLifetime lifeTime + XRepositoryType repositoryType, + Type contextType = null, + ServiceLifetime lifeTime = ServiceLifetime.Scoped ) { // @@ -67,7 +154,7 @@ namespace xWebinarService.DI if (!isServicesExists) { // - Log("AddWebinarService failed, services not provided ..."); + Log("Service Registration failed, services not provided ..."); throw exception; } @@ -77,60 +164,103 @@ namespace xWebinarService.DI if (!isLifetimeExists) { // - Log("AddWebinarService failed, lifetime not provided ..."); + Log("Service Registration failed, lifetime not provided ..."); throw exception; } // - // Check Dependencies Exists ... - var isDependenciesPassed = !services - .GetRegisteredService() - .IsNull() && - !services.GetRegisteredService().IsNull() && - !services.GetRegisteredService().IsNull(); - if (!isDependenciesPassed) + // Validate Repository Type ... + var isRepositoryTypeValid = + (repositoryType == XRepositoryType.EF && + !contextType.IsNull()) || + ((repositoryType == XRepositoryType.Mongo || + repositoryType == XRepositoryType.InMemory) && + contextType.IsNull()); + if (!isRepositoryTypeValid) { // - Log("AddFileService failed due Dependencies Issues, IXTagProvider, IXFileProvider, IXWebinarSubscriberRepository not provided ..."); + Log("Service Registration failed, Invalid Repository Type and Context Type ..."); throw exception; } // - // Check Repository Exists ... - var isRepositoryExists = !services - .GetRegisteredService() - .IsNull(); - if (!isRepositoryExists) + // Maske Instance of Repository Descriptor + // Based on Provided Type ... + switch (repositoryType) { // - Log("AddWebinarService failed, IXWebinarRepository not provided ..."); - throw exception; + case XRepositoryType.EF: + // + webinarDescriptor = typeof(XWebinarServiceHelper) + .InvokeGenericMethod( + methodName: "GetXWebinarEFRepositoryDescriptor", + runtimeType: contextType, + args: null + ); + + // + webinarSubscriberDescriptor = typeof(XWebinarServiceHelper) + .InvokeGenericMethod( + methodName: "GetXWebinarSubscriberEFRepositoryDescriptor", + runtimeType: contextType, + args: null + ); + break; + + // + case XRepositoryType.Mongo: + webinarDescriptor = XWebinarServiceHelper.GetXWebinarMongoRepositoryDescriptor(); + webinarSubscriberDescriptor = XWebinarServiceHelper.GetXWebinarSubscriberMongoRepositoryDescriptor(); + break; + + // + case XRepositoryType.InMemory: + webinarDescriptor = XWebinarServiceHelper.GetXWebinarInMemoryRepositoryDescriptor(); + webinarSubscriberDescriptor = XWebinarServiceHelper.GetXWebinarSubscriberInMemoryRepositoryDescriptor(); + break; } // - // Register Webinar Group In Memory Repository ... - services.AddSingleton, XGuidKeyGenerator>(); - services.Add(new ServiceDescriptor(typeof(IXWebinarGroupStore), typeof(XWebinarGroupStore), ServiceLifetime.Singleton)); + // Register xWebinar Repository Descriptor ... + services.AddXRepository( + lifeTime: lifeTime, + descriptor: webinarDescriptor + ); + + services.AddXRepository( + lifeTime: lifeTime, + descriptor: webinarSubscriberDescriptor + ); // - // Register Resource Providers ... - services.Add(new ServiceDescriptor(typeof(IXWebinarTitleResourceProvider), typeof(XWebinarTitleResourceProvider), lifeTime)); - services.Add(new ServiceDescriptor(typeof(IXWebinarDescriptionResourceProvider), typeof(XWebinarDescriptionResourceProvider), lifeTime)); + // Register Dto Services ... + services.Add( + new ServiceDescriptor(typeof(IXWebinarServiceProvider), typeof(XWebinarServiceProvider), lifeTime) + ); + services.Add( + new ServiceDescriptor(typeof(IXWebinarRepositoryService), typeof(XWebinarRepositoryService), lifeTime) + ); + services.Add( + new ServiceDescriptor(typeof(IXWebinarRepositoryProvider), typeof(XWebinarRepositoryProvider), lifeTime) + ); + + services.Add( + new ServiceDescriptor(typeof(IXWebinarSubscriberServiceProvider), typeof(XWebinarSubscriberServiceProvider), lifeTime) + ); + services.Add( + new ServiceDescriptor(typeof(IXWebinarSubscriberRepositoryService), typeof(XWebinarSubscriberRepositoryService), lifeTime) + ); + services.Add( + new ServiceDescriptor(typeof(IXWebinarSubscriberRepositoryProvider), typeof(XWebinarSubscriberRepositoryProvider), lifeTime) + ); // - // Register Webinar Tag Provider ... - services.Add(new ServiceDescriptor(typeof(IXWebinarTagProvider), typeof(XWebinarTagProvider), lifeTime)); + // services.Add( + // new ServiceDescriptor(typeof(IXWebinarProvider), typeof(XWebinarProvider), lifeTime) + // ); // - // Register Webinar File Provider ... - services.Add(new ServiceDescriptor(typeof(IXWebinarFileProvider), typeof(XWebinarFileProvider), lifeTime)); - - // - // Register Main Provider ... - services.Add(new ServiceDescriptor(typeof(IXWebinarProvider), typeof(XWebinarProvider), lifeTime)); - - // - Log("AddWebinarService Succeed ..."); + Log("Service Regitration Succeed ..."); } #endregion } diff --git a/DataHelper/Events/XWebinarEvents.cs b/DataHelper/Events/XWebinarEvents.cs deleted file mode 100644 index 9a855c2..0000000 --- a/DataHelper/Events/XWebinarEvents.cs +++ /dev/null @@ -1,9 +0,0 @@ -using xDataService.Events; -using xWebinarService.Interfaces.Entities; -using xWebinarService.Models.Entities; - -namespace xWebinarService.DataHelper.Events -{ - public class XWebinarEvents : XBaseRepositoryEvents, IXWebinarEvents - { } -} \ No newline at end of file diff --git a/DataHelper/Events/XWebinarSubscriberEvents.cs b/DataHelper/Events/XWebinarSubscriberEvents.cs deleted file mode 100644 index 79814fe..0000000 --- a/DataHelper/Events/XWebinarSubscriberEvents.cs +++ /dev/null @@ -1,9 +0,0 @@ -using xDataService.Events; -using xWebinarService.Interfaces.Entities; -using xWebinarService.Models.Entities; - -namespace xWebinarService.DataHelper.Events -{ - public class XWebinarSubscriberEvents : XBaseRepositoryEvents, IXWebinarSubscriberEvents - { } -} \ No newline at end of file diff --git a/Providers/.gitkeep b/Extensions/.gitkeep similarity index 100% rename from Providers/.gitkeep rename to Extensions/.gitkeep diff --git a/Extensions/xWebinarServiceExtensions.cs b/Extensions/xWebinarServiceExtensions.cs deleted file mode 100644 index f13e31d..0000000 --- a/Extensions/xWebinarServiceExtensions.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace xWebinarService.Extensions { - public static class xWebinarServiceExtensions { } -} \ No newline at end of file diff --git a/Helpers/XWebinarServiceHelper.cs b/Helpers/XWebinarServiceHelper.cs new file mode 100644 index 0000000..07d4e27 --- /dev/null +++ b/Helpers/XWebinarServiceHelper.cs @@ -0,0 +1,550 @@ +using System; +using GraphQL.Types; +using xDataService.Db; +using xDataService.Models; +using xDataService.Providers; +using xWebinarService.Interfaces; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; +using xWebinarService.Providers.Entities; +using xWebinarService.Providers.GraphQL; + +namespace xWebinarService.Helpers +{ + public static class XWebinarServiceHelper + { + // + #region XWebinar ... + // + #region EF Repository Descriptor Provider(s) ... + public static XEFRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarEFRepository, + TContext + > GetXWebinarEFRepositoryDescriptor() + where TContext : XDbContext + { + // + var result = new XEFRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarEFRepository, + TContext + >(); + + // + return result; + } + + public static XEFRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarEFRepository, + TContext, + IXWebinarSeeder, + TSeederImplementation + > GetXWebinarEFRepositoryDescriptor() + where TContext : XDbContext + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XEFRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarEFRepository, + TContext, + IXWebinarSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + + // + #region Mongo Repository Descriptor Provider(s) ... + public static XMongoRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarMongoRepository + > GetXWebinarMongoRepositoryDescriptor() + { + // + var result = new XMongoRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarMongoRepository + >(); + + // + return result; + } + + public static XMongoRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarMongoRepository, + IXWebinarSeeder, + TSeederImplementation + > GetXWebinarMongoRepositoryDescriptor() + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XMongoRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarMongoRepository, + IXWebinarSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + + // + #region InMemory Repository Descriptor Provider(s) ... + public static XInMemoryRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarInMemoryRepository + > GetXWebinarInMemoryRepositoryDescriptor() + { + // + var result = new XInMemoryRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarInMemoryRepository + >(); + + // + return result; + } + + public static XInMemoryRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarInMemoryRepository, + IXWebinarSeeder, + TSeederImplementation + > GetXWebinarInMemoryRepositoryDescriptor() + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XInMemoryRepositoryDescriptor< + XWebinar, + Guid, + IXWebinarKeyGenerator, + XWebinarKeyGenerator, + IXWebinarRepositoryEvents, + XWebinarRepositoryEvents, + XWebinarGraphType, + GuidGraphType, + XWebinarGraphQuery, + IXWebinarGraphQLTypeHelper, + XWebinarGraphQLTypeHelper, + XWebinarGraphSchema, + IXWebinarRepository, + XWebinarInMemoryRepository, + IXWebinarSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + #endregion + + // + #region XWebinarSubscriber ... + // + #region EF Repository Descriptor Provider(s) ... + public static XEFRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberEFRepository, + TContext + > GetXWebinarSubscriberEFRepositoryDescriptor() + where TContext : XDbContext + { + // + var result = new XEFRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberEFRepository, + TContext + >(); + + // + return result; + } + + public static XEFRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberEFRepository, + TContext, + IXWebinarSubscriberSeeder, + TSeederImplementation + > GetXWebinarSubscriberEFRepositoryDescriptor() + where TContext : XDbContext + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XEFRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberEFRepository, + TContext, + IXWebinarSubscriberSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + + // + #region Mongo Repository Descriptor Provider(s) ... + public static XMongoRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberMongoRepository + > GetXWebinarSubscriberMongoRepositoryDescriptor() + { + // + var result = new XMongoRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberMongoRepository + >(); + + // + return result; + } + + public static XMongoRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberMongoRepository, + IXWebinarSubscriberSeeder, + TSeederImplementation + > GetXWebinarSubscriberMongoRepositoryDescriptor() + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XMongoRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberMongoRepository, + IXWebinarSubscriberSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + + // + #region InMemory Repository Descriptor Provider(s) ... + public static XInMemoryRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberInMemoryRepository + > GetXWebinarSubscriberInMemoryRepositoryDescriptor() + { + // + var result = new XInMemoryRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberInMemoryRepository + >(); + + // + return result; + } + + public static XInMemoryRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberInMemoryRepository, + IXWebinarSubscriberSeeder, + TSeederImplementation + > GetXWebinarSubscriberInMemoryRepositoryDescriptor() + where TSeederImplementation : XBaseDbSeeder + { + // + var result = new XInMemoryRepositoryDescriptor< + XWebinarSubscriber, + int, + IXWebinarSubscriberKeyGenerator, + XWebinarSubscriberKeyGenerator, + IXWebinarSubscriberRepositoryEvents, + XWebinarSubscriberRepositoryEvents, + XWebinarSubscriberGraphType, + IntGraphType, + XWebinarSubscriberGraphQuery, + IXWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphQLTypeHelper, + XWebinarSubscriberGraphSchema, + IXWebinarSubscriberRepository, + XWebinarSubscriberInMemoryRepository, + IXWebinarSubscriberSeeder, + TSeederImplementation + >(); + + // + return result; + } + #endregion + #endregion + } +} \ No newline at end of file diff --git a/Hubs/XWebinarEntityHub.cs b/Hubs/XWebinarEntityHub.cs deleted file mode 100644 index c96bc81..0000000 --- a/Hubs/XWebinarEntityHub.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; -using xPushService.Base; -using xWebinarService.Models.Entities; - -namespace xWebinarService.Hubs -{ - public class XWebinarEntityHub : XBaseEntityHub - { - // - #region Constructor ... - public XWebinarEntityHub(ILogger logger) : base(logger) - { } - #endregion - } -} \ No newline at end of file diff --git a/Hubs/XWebinarHub.cs b/Hubs/XWebinarHub.cs deleted file mode 100644 index b281e16..0000000 --- a/Hubs/XWebinarHub.cs +++ /dev/null @@ -1,562 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.Logging; -using xCommons.Extensions; -using xExceptions.Constants; -using xPushService.Base; -using xPushService.Extensions; -using xWebinarService.Constants; -using xWebinarService.Interfaces; -using xWebinarService.Models.Entities; - -namespace xWebinarService.Hubs -{ - public class XWebinarHub : XBaseWebRTCHub - { - // - #region Props ... - public readonly IXWebinarProvider webinarProvider; - private readonly IXWebinarGroupStore webinarGroupStore; - #endregion - - // - #region Constructor ... - public XWebinarHub( - ILogger logger, - IXWebinarProvider webinarProvider, - IXWebinarGroupStore webinarGroupStore - ) : base(logger) - { - this.webinarProvider = webinarProvider; - this.webinarGroupStore = webinarGroupStore; - } - #endregion - - // - #region Actions ... - /// - /// a Webinar Owner Open Webinar for Broadcasting ... - /// - /// - /// - [Authorize] - public async Task WebinarOpened(Guid webinarId) - { - // - // Validate Arg ... - var isValid = !webinarId.IsNull() && - !webinarId.IsDefaultGuid(); - if (!isValid) - { - // - logger.LogError($"Invalid Webinar Provider ..."); - return; - } - - // - // Reading and Validate Requirements ... - var userInfo = Context.GetUserInfo(); - var connectionId = Context.ConnectionId; - isValid = !userInfo.IsNullOrDefault() && - !connectionId.IsNullOrEmpty(); - if (!isValid) - { - // - logger.LogError($"Invaid User Info ..."); - return; - } - - // - // Retrieve Webinar Model and Validate it Exists ... - try - { - // - // Retrieve Webinar ... - var webinar = await webinarProvider.GetWebinar(webinarId); - - // - // Validate Webinar ... - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - // - XException.NotFound.Throw(); - logger.LogError($"Webinar Not Found ..."); - } - - // - // Validate User is Webinar Owner ... - isValid = - !userInfo.UserId.IsNullOrEmpty() && - userInfo.UserId == webinar.OwnerId; - if (!isValid) - { - // - XException.NotAllowed.Throw(); - logger.LogError($"Not Allowed to Present Webinar ..."); - } - - // - // Now try to Enable Webinar and Notify Webinars Client Which it's Open ... - webinar.Enabled = true; - webinar = await webinarProvider.UpdateWebinar(webinar); - await Clients.AllExcept(connectionId).SendAsync(XWebinarHubAction.WebinarOpened.GetStringValue(), webinarId); - - // - // Create a Group and Put User on it ... - await Groups.AddToGroupAsync(connectionId, webinarId.ToString()); - - // - // Check Exists or not ... - var connection = new XHubConnectionDto - { - UserId = userInfo.UserId, - ConnectionId = connectionId, - Username = userInfo.UserName, - }; - var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId); - if (!groupEntity.IsNullOrDefault()) - { - // - // Update ... - groupEntity.Connections.Clear(); - groupEntity.Connections.Add(connection); - await webinarGroupStore.UpdateAsync(groupEntity.Id, groupEntity); - } - else - { - // - // Add ... - groupEntity = new XWebinarGroupEntity - { - WebinarId = webinarId - }; - groupEntity.Connections.Add(connection); - await webinarGroupStore.AddAsync(groupEntity); - } - } - catch { } - } - - /// - /// Close a Webinar by it's Owner ... - /// - /// - /// - [Authorize] - public async Task WebinarClosed(Guid webinarId) - { - // - // Validate Arg ... - var isValid = !webinarId.IsNull() && - !webinarId.IsDefaultGuid(); - if (!isValid) - { - // - logger.LogError($"Invalid Webinar Provider ..."); - return; - } - - // - // Reading and Validate Requirements ... - var userInfo = Context.GetUserInfo(); - var connectionId = Context.ConnectionId; - isValid = !userInfo.IsNullOrDefault() && - !connectionId.IsNullOrEmpty(); - if (!isValid) - { - // - logger.LogError($"Invaid User Info ..."); - return; - } - - // - // Retrieve Webinar Model and Validate it Exists ... - try - { - // - // Retrieve Webinar ... - var webinar = await webinarProvider.GetWebinar(webinarId); - - // - // Validate Webinar ... - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - // - XException.NotFound.Throw(); - logger.LogError($"Webinar Not Found ..."); - } - - // - // Validate User is Webinar Owner ... - isValid = - !userInfo.UserId.IsNullOrEmpty() && - userInfo.UserId == webinar.OwnerId; - if (!isValid) - { - // - XException.NotAllowed.Throw(); - logger.LogError($"Not Allowed to Present Webinar ..."); - } - - // - // Now try to Enable Webinar and Notify Webinars Client Which it's Open ... - webinar.Enabled = false; - webinar = await webinarProvider.UpdateWebinar(webinar); - await Clients.AllExcept(connectionId).SendAsync(XWebinarHubAction.WebinarClosed.GetStringValue(), webinarId); - - // - var webinarName = webinarId.ToString(); - await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.WebinarClosed.ToString()); - await Groups.RemoveFromGroupAsync(connectionId, webinarName); - - // - // Check Exists or not ... - var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId); - if (!groupEntity.IsNullOrDefault()) - { - await webinarGroupStore.RemoveAsync(groupEntity.Id); - } - } - catch { } - } - - /// - /// a Webinar Subscriber Joined to Opened Webinar ... - /// - /// - /// - [Authorize] - public async Task ViewerJoined(Guid webinarId) - { - // - // Validate ... - var isValid = !webinarId.IsNull() && - !webinarId.IsDefaultGuid(); - if (!isValid) - { - // - logger.LogError($"Invalid Webinar Provider ..."); - return; - } - - // - // Retrieve requirements ... - var userInfo = Context.GetUserInfo(); - var connectionId = Context.ConnectionId; - isValid = !userInfo.IsNullOrDefault() && - !connectionId.IsNullOrEmpty(); - if (!isValid) - { - // - logger.LogError($"Invaid User Info ..."); - return; - } - - // - try - { - // - // Reading Webinar ... - var webinar = await webinarProvider.GetWebinar(webinarId); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - // - logger.LogError($"Webinar Not Found ..."); - XException.NotFound.Throw(); - } - - // - // Validate User is Webinar Subscriber ... - // Or Webinar is Open ... - if (webinar.Type != XWebinarType.Public) - { - // - isValid = await webinarProvider.IsSubscribed( - webinarId: webinarId, - subscriberId: userInfo.UserId - ); - if (!isValid) - { - // - logger.LogError("User Not Have Permission to Join Webinar ..."); - XException.NotAllowed.Throw(); - } - } - - // - var webinarName = webinarId.ToString(); - - // - // Add User to Webinar ... - await Groups.AddToGroupAsync(connectionId, webinarName); - - // - // Notify Other Users which a Viewer Joined ... - await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.ViewerJoined.GetStringValue(), - connectionId, - webinarId, - userInfo.UserId, - userInfo.UserName - ); - - // - // Check Exists or not ... - var connection = new XHubConnectionDto - { - UserId = userInfo.UserId, - ConnectionId = connectionId, - Username = userInfo.UserName, - }; - var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId); - if (!groupEntity.IsNullOrDefault()) - { - // - // Check Current User ID Exists ... - var userConnection = groupEntity.Connections.FirstOrDefault(c => c.UserId == userInfo.UserId); - if (!userConnection.IsNullOrDefault()) - { - userConnection.ConnectionId = connectionId; - } - else - { - groupEntity.Connections.Add(connection); - } - - // - await webinarGroupStore.UpdateAsync(groupEntity.Id, groupEntity); - } - } - catch - { } - } - - /// - /// a Webina Subscriber Lefts Group ... - /// - /// - /// - [Authorize] - public async Task ViewerLeaved(Guid webinarId) - { - // - // Validate ... - var isValid = !webinarId.IsNull() && - !webinarId.IsDefaultGuid(); - if (!isValid) - { - // - logger.LogError($"Invalid Webinar Provider ..."); - return; - } - - // - // Retrieve requirements ... - var userInfo = Context.GetUserInfo(); - var connectionId = Context.ConnectionId; - isValid = !userInfo.IsNullOrDefault() && - !connectionId.IsNullOrEmpty(); - if (!isValid) - { - // - logger.LogError($"Invaid User Info ..."); - return; - } - - // - try - { - // - // Reading Webinar ... - var webinar = await webinarProvider.GetWebinar(webinarId); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - // - logger.LogError($"Webinar Not Found ..."); - XException.NotFound.Throw(); - } - - // - // Validate User is Webinar Subscriber ... - // Or Webinar is Open ... - if (webinar.Type != XWebinarType.Public) - { - // - isValid = await webinarProvider.IsSubscribed( - webinarId: webinarId, - subscriberId: userInfo.UserId - ); - if (!isValid) - { - // - logger.LogError("User Not Have Permission to Join Webinar ..."); - XException.NotAllowed.Throw(); - } - } - - // - var webinarName = webinarId.ToString(); - - // - // Add User to Webinar ... - await Groups.RemoveFromGroupAsync(connectionId, webinarName); - - // - // Notify Other Users which a Viewer Leaved ... - await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.ViewerLeaved.GetStringValue(), - connectionId, - webinarId, - userInfo.UserId, - userInfo.UserName - ); - - // - // Check Exists or not ... - var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId); - if (!groupEntity.IsNullOrDefault()) - { - // - // Check Current User ID Exists ... - var userConnection = groupEntity.Connections.FirstOrDefault(c => c.ConnectionId == connectionId); - if (!userConnection.IsNullOrDefault()) - { - groupEntity.Connections.Remove(userConnection); - } - - // - await webinarGroupStore.UpdateAsync(groupEntity.Id, groupEntity); - } - } - catch - { } - } - - /// - /// Return a Collection of Webinars Visitors ... - /// - /// - /// - [Authorize] - public async Task> WebinarVisitors(Guid webinarId) - { - // - var result = new List(); - - // - // Reading and Validate Requirements ... - var userInfo = Context.GetUserInfo(); - var connectionId = Context.ConnectionId; - - - // - // Check Group Exists ... - var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId); - if (!groupEntity.IsNullOrDefault()) - { - // - // Validate Requester is a Viewer ... - var connection = groupEntity.Connections.FirstOrDefault(c => c.ConnectionId == connectionId || - c.UserId == userInfo.UserId - ); - if (!connection.IsNullOrDefault()) - { - result = groupEntity.Connections; - } - } - - // - return result; - } - - /// - /// Send a Message to Specified Webinar ... - /// - /// - /// - /// - [Authorize] - public async Task Message(Guid webinarId, string message) - { - // - // Validate ... - var isValid = !webinarId.IsNull() && - !webinarId.IsDefaultGuid(); - if (!isValid) - { - // - logger.LogError($"Invalid Webinar Provider ..."); - return; - } - - // - // Retrieve requirements ... - var userInfo = Context.GetUserInfo(); - var connectionId = Context.ConnectionId; - isValid = !userInfo.IsNullOrDefault() && - !connectionId.IsNullOrEmpty(); - if (!isValid) - { - // - logger.LogError($"Invaid User Info ..."); - return; - } - - // - try - { - // - // Reading Webinar ... - var webinar = await webinarProvider.GetWebinar(webinarId); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - // - logger.LogError($"Webinar Not Found ..."); - XException.NotFound.Throw(); - } - - // - // Validate User is Webinar Owner or Subscriber ... - // Or Webinar is Open ... - if (webinar.Type != XWebinarType.Public) - { - // - isValid = userInfo.UserId == webinar.OwnerId || - (await webinarProvider.IsSubscribed( - webinarId: webinarId, - subscriberId: userInfo.UserId - )); - if (!isValid) - { - // - logger.LogError("User Not Have Permission to Join Webinar ..."); - XException.NotAllowed.Throw(); - } - } - - // - var webinarName = webinarId.ToString(); - - // - // Notify Other Users which a Viewer Leaved ... - await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.Message.GetStringValue(), - connectionId, - userInfo.UserId, - userInfo.UserName, - message - ); - } - catch - { } - } - #endregion - } -} \ No newline at end of file diff --git a/Interfaces/Dtos/IXWebinarDtoHub.cs b/Interfaces/Dtos/IXWebinarDtoHub.cs new file mode 100644 index 0000000..0a54f16 --- /dev/null +++ b/Interfaces/Dtos/IXWebinarDtoHub.cs @@ -0,0 +1,10 @@ +using System; +using xPushService.Interfaces; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Dtos +{ + public interface IXWebinarDtoHub : IXBaseDtoHub + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXWebinarRepositoryService.cs b/Interfaces/Dtos/IXWebinarRepositoryService.cs new file mode 100644 index 0000000..4787063 --- /dev/null +++ b/Interfaces/Dtos/IXWebinarRepositoryService.cs @@ -0,0 +1,10 @@ +using System; +using xDataService.Interfaces; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Dtos +{ + public interface IXWebinarRepositoryService : IXBaseRepositoryService + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXWebinarServiceProvider.cs b/Interfaces/Dtos/IXWebinarServiceProvider.cs new file mode 100644 index 0000000..cfd146c --- /dev/null +++ b/Interfaces/Dtos/IXWebinarServiceProvider.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using xPushService.Interfaces; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; +using xWebinarService.Providers.Dtos; + +namespace xWebinarService.Interfaces.Dtos +{ + public interface IXWebinarServiceProvider : IXBaseDtoProvider + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXWebinarSubscriberDtoHub.cs b/Interfaces/Dtos/IXWebinarSubscriberDtoHub.cs new file mode 100644 index 0000000..ef47f00 --- /dev/null +++ b/Interfaces/Dtos/IXWebinarSubscriberDtoHub.cs @@ -0,0 +1,9 @@ +using xPushService.Interfaces; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Dtos +{ + public interface IXWebinarSubscriberDtoHub : IXBaseDtoHub + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXWebinarSubscriberRepositoryService.cs b/Interfaces/Dtos/IXWebinarSubscriberRepositoryService.cs new file mode 100644 index 0000000..b9043c0 --- /dev/null +++ b/Interfaces/Dtos/IXWebinarSubscriberRepositoryService.cs @@ -0,0 +1,9 @@ +using xDataService.Interfaces; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Dtos +{ + public interface IXWebinarSubscriberRepositoryService : IXBaseRepositoryService + { } +} \ No newline at end of file diff --git a/Interfaces/Dtos/IXWebinarSubscriberServiceProvider.cs b/Interfaces/Dtos/IXWebinarSubscriberServiceProvider.cs new file mode 100644 index 0000000..8cce27f --- /dev/null +++ b/Interfaces/Dtos/IXWebinarSubscriberServiceProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace xWebinarService.Interfaces.Dtos +{ + public interface IXWebinarSubscriberServiceProvider + { + + } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarEntityHub.cs b/Interfaces/Entities/IXWebinarEntityHub.cs new file mode 100644 index 0000000..8603127 --- /dev/null +++ b/Interfaces/Entities/IXWebinarEntityHub.cs @@ -0,0 +1,9 @@ +using System; +using xPushService.Interfaces; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Entities +{ + public interface IXWebinarEntityHub : IXBaseEntityHub + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarSubscriberEvents.cs b/Interfaces/Entities/IXWebinarKeyGenerator.cs similarity index 58% rename from Interfaces/Entities/IXWebinarSubscriberEvents.cs rename to Interfaces/Entities/IXWebinarKeyGenerator.cs index abcc45c..2dcdc0e 100644 --- a/Interfaces/Entities/IXWebinarSubscriberEvents.cs +++ b/Interfaces/Entities/IXWebinarKeyGenerator.cs @@ -1,8 +1,9 @@ +using System; using xDataService.Interfaces; using xWebinarService.Models.Entities; namespace xWebinarService.Interfaces.Entities { - public interface IXWebinarSubscriberEvents : IXBaseRepositoryEvents + public interface IXWebinarKeyGenerator : IXKeyGenerator { } } \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarEvents.cs b/Interfaces/Entities/IXWebinarRepositoryEvents.cs similarity index 60% rename from Interfaces/Entities/IXWebinarEvents.cs rename to Interfaces/Entities/IXWebinarRepositoryEvents.cs index 708e4a5..b4e256a 100644 --- a/Interfaces/Entities/IXWebinarEvents.cs +++ b/Interfaces/Entities/IXWebinarRepositoryEvents.cs @@ -3,6 +3,6 @@ using xWebinarService.Models.Entities; namespace xWebinarService.Interfaces.Entities { - public interface IXWebinarEvents : IXBaseRepositoryEvents + public interface IXWebinarRepositoryEvents : IXBaseRepositoryEvents { } } \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarRepositoryProvider.cs b/Interfaces/Entities/IXWebinarRepositoryProvider.cs new file mode 100644 index 0000000..cc66d82 --- /dev/null +++ b/Interfaces/Entities/IXWebinarRepositoryProvider.cs @@ -0,0 +1,10 @@ +using System; +using xPushService.Interfaces; +using xWebinarService.Models.Entities; +using xWebinarService.Providers.Entities; + +namespace xWebinarService.Interfaces.Entities +{ + public interface IXWebinarRepositoryProvider : IXBaseEntityProvider + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarSubscriberEntityHub.cs b/Interfaces/Entities/IXWebinarSubscriberEntityHub.cs new file mode 100644 index 0000000..b987c3f --- /dev/null +++ b/Interfaces/Entities/IXWebinarSubscriberEntityHub.cs @@ -0,0 +1,8 @@ +using xPushService.Interfaces; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Entities +{ + public interface IXWebinarSubscriberEntityHub : IXBaseEntityHub + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarSubscriberKeyGenerator.cs b/Interfaces/Entities/IXWebinarSubscriberKeyGenerator.cs new file mode 100644 index 0000000..d8df4ae --- /dev/null +++ b/Interfaces/Entities/IXWebinarSubscriberKeyGenerator.cs @@ -0,0 +1,8 @@ +using xDataService.Interfaces; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Entities +{ + public interface IXWebinarSubscriberKeyGenerator : IXKeyGenerator + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarSubscriberRepositoryEvents.cs b/Interfaces/Entities/IXWebinarSubscriberRepositoryEvents.cs new file mode 100644 index 0000000..802d31c --- /dev/null +++ b/Interfaces/Entities/IXWebinarSubscriberRepositoryEvents.cs @@ -0,0 +1,8 @@ +using xDataService.Interfaces; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces.Entities +{ + public interface IXWebinarSubscriberRepositoryEvents : IXBaseRepositoryEvents + { } +} \ No newline at end of file diff --git a/Interfaces/Entities/IXWebinarSubscriberRepositoryProvider.cs b/Interfaces/Entities/IXWebinarSubscriberRepositoryProvider.cs new file mode 100644 index 0000000..5d95702 --- /dev/null +++ b/Interfaces/Entities/IXWebinarSubscriberRepositoryProvider.cs @@ -0,0 +1,9 @@ +using xPushService.Interfaces; +using xWebinarService.Models.Entities; +using xWebinarService.Providers.Entities; + +namespace xWebinarService.Interfaces.Entities +{ + public interface IXWebinarSubscriberRepositoryProvider : IXBaseEntityProvider + { } +} \ No newline at end of file diff --git a/Interfaces/IXWebinarDescriptionResourceProvider.cs b/Interfaces/IXWebinarDescriptionResourceProvider.cs deleted file mode 100644 index 68169c5..0000000 --- a/Interfaces/IXWebinarDescriptionResourceProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -using xStringService.Interfaces; - -namespace xWebinarService.Interfaces -{ - public interface IXWebinarDescriptionResourceProvider : IXBaseStringResourceProvider - { } -} \ No newline at end of file diff --git a/Interfaces/IXWebinarFileProvider.cs b/Interfaces/IXWebinarFileProvider.cs deleted file mode 100644 index 08c6b9e..0000000 --- a/Interfaces/IXWebinarFileProvider.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using xFileService.Interfaces; - -namespace xWebinarService.Interfaces -{ - public interface IXWebinarFileProvider : IXBaseFileProvider - { } -} \ No newline at end of file diff --git a/Interfaces/IXWebinarProvider.cs b/Interfaces/IXWebinarProvider.cs deleted file mode 100644 index 6f3085f..0000000 --- a/Interfaces/IXWebinarProvider.cs +++ /dev/null @@ -1,395 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SignalR; -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; -using xWebinarService.Models.Entities; -using XFileDto = xFileService.Models.Dtos.XFileDto; - -namespace xWebinarService.Interfaces -{ - public interface IXWebinarProvider - { - // - #region Props ... - IHubContext Hub { get; } - IXIdentityProvider IdentityProvider { get; } - IXWebinarRepository WebinarRepository { get; } - IXWebinarTagProvider WebinarTagProvider { get; } - IXWebinarFileProvider WebinarFileProvider { get; } - XDataServiceConfiguration DataSercviceConfiguration { get; } - IXWebinarTitleResourceProvider TitleResourceProvider { get; } - IXWebinarSubscriberRepository WebinarSubscriberRepository { get; } - IXWebinarDescriptionResourceProvider DescriptionResourceProvider { get; } - #endregion - - // - #region Tools ... - /// - /// Converts Specified XWebinar Entity to it's Corresponding Dto Presentation - /// and also Fill Owner and Title/Description Resources ... - /// - /// - /// - Task ToXWebinarDto(XWebinar model); - - /// - /// Converts Specified WebinarSubscriber Entity to it's Dto Presentation ... - /// - /// - /// - Task ToXWebinarSubscriberDto(XWebinarSubscriber model); - #endregion - - // - #region Actions ... - /// - /// Create Webinar ... - /// - /// - /// - /// - /// - /// - /// - Task CreateWebinar( - XWebinarDto item, - IEnumerable tags = null, - IFormFileCollection files = null, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ); - - /// - /// Update a Webinar ... - /// - /// - /// - /// - /// - Task UpdateWebinar( - XWebinarDto item, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ); - - /// - /// Retrieve Specified Webinar ... - /// - /// - /// - Task GetWebinar(Guid id); - - /// - /// Retrieve all Exists Webinars ... - /// - /// - Task> GetWebinars(); - - /// - /// Query Webinars ... - /// - /// - /// - Task> QueryWebinars(XQuery query); - - /// - /// Conditional Query Webinars ... - /// - /// - /// - /// - Task> ConditionalQueryWebinars( - Expression> whereClause, - XQuery query - ); - - /// - /// Query Owned Webinars ... - /// - /// - /// - Task> QueryOwnedWebinars( - XQuery query, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Query Joinable Webinars ... - /// - /// - /// - Task> QueryJoinableWebinars( - XQuery query, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Remove Specified Webinar ... - /// - /// - /// - /// - /// - Task RemoveWebinar( - Guid webinarId, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ); - #endregion - - // - #region WebinarSubscriber ... - /// - /// Subscribe a User to Webinar ... - /// - /// - /// - /// - /// - /// - Task Subscribe( - Guid webinarId, - string subscriberId, - string connectionId = null, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Check Specified User Subscribed on a Webinar or not ... - /// - /// - /// - /// - /// - Task IsSubscribed( - Guid webinarId, - string subscriberId, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Unsubscribe Specified User from a Specified Webinar ... - /// - /// - /// - /// - /// - /// - Task Unsubscribe( - Guid webinarId, - string subscriberId, - string connectionId = null, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Retrieve Specified Subscriber ... - /// - /// - /// - /// - /// - Task GetSubscriber( - Guid webinarId, - string subscriberId, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Get all Specified Webinars Subscribers ... - /// - /// - /// - /// - Task> GetSubscribers( - Guid webinarId, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Query Specified Webinar's Subscribers ... - /// - /// - /// - /// - /// - Task> QuerySubscribers( - Guid webinarId, - XQuery query, - XUserClaimsInfoDto userInfo = null - ); - #endregion - - // - #region File Actions ... - /// - /// Upload Files ... - /// - /// - /// - /// - /// - /// - Task> UploadFiles( - Guid id, - IFormFileCollection files, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ); - - /// - /// Get Webinar Files ... - /// - /// - /// - /// - Task> GetFiles( - Guid id, - XUserClaimsInfoDto userInfo = null - ); - - /// - /// Stream Specified File ... - /// - /// - /// - Task StreamFile( - Guid id, - Guid fileId - ); - - /// - /// Stream Specified File ... - /// - /// - /// - 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 - - // - #region Tags Actions ... - /// - /// Attach Tag to Specified File ... - /// - /// - /// - /// - /// - /// - /// - Task AttachTag( - Guid id, - string tag, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceAttachToFiles = true - ); - - /// - /// Detach Tag fro Specified File ... - /// - /// - /// - /// - /// - /// - /// - Task DetachTag( - Guid id, - string tag, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceDetachFromFiles = true - ); - - /// - /// Attach Tags for Specified File ... - /// - /// - /// - /// - /// - /// - /// - Task AttachTags( - Guid id, - string tags, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceAttachToFiles = true - ); - - /// - /// Detach Tags for Specified File ... - /// - /// - /// if nulls, detach all tags ... - /// - /// - /// - /// - Task DetachTags( - Guid id, - string tags, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceDetachFromFiles = true - ); - - /// - /// Retrieve Specified Webinar's Tags ... - /// - /// - /// - /// - Task> GetTags( - Guid id, - XUserClaimsInfoDto userInfo = null - ); - #endregion - } -} \ No newline at end of file diff --git a/Interfaces/IXWebinarGroupStore.cs b/Interfaces/IXWebinarSeeder.cs similarity index 53% rename from Interfaces/IXWebinarGroupStore.cs rename to Interfaces/IXWebinarSeeder.cs index b238400..a60320e 100644 --- a/Interfaces/IXWebinarGroupStore.cs +++ b/Interfaces/IXWebinarSeeder.cs @@ -4,8 +4,6 @@ using xWebinarService.Models.Entities; namespace xWebinarService.Interfaces { - public interface IXWebinarGroupStore : IXBaseRepository - { - - } + public interface IXWebinarSeeder : IXBaseDbSeeder + { } } \ No newline at end of file diff --git a/Interfaces/IXWebinarServiceControllerActions.cs b/Interfaces/IXWebinarServiceControllerActions.cs deleted file mode 100644 index d76ad8b..0000000 --- a/Interfaces/IXWebinarServiceControllerActions.cs +++ /dev/null @@ -1,266 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using xModels.Dtos; -using XFileDto = xFileService.Models.Dtos.XFileDto; -using xWebinarService.Models.Dtos; -using xTagService.Models.Dtos; - -namespace xWebinarService.Interfaces -{ - /// - /// an Interface to Provides Webinar Provider Actions ... - /// - public interface IXWebinarServiceControllerActions - { - // - #region Actions ... - /// - /// Create Webinar ... - /// - /// - /// - /// - /// - Task> CreateWebinar( - [FromForm] XWebinarDto item, - [FromQuery] string tags = null, - [FromForm] IFormFileCollection files = null - ); - - /// - /// Update a Webinar ... - /// - /// - /// - /// - Task> UpdateWebinar( - [FromRoute] Guid id, - [FromBody] XWebinarDto item - ); - - /// - /// Retrieve Specified Webinar ... - /// - /// - /// - Task> GetWebinar( - [FromRoute] Guid id - ); - - /// - /// Retrieve all Exists Webinars ... - /// - /// - Task>> GetWebinars(); - - /// - /// Query Webinars ... - /// - /// - /// - Task>> QueryWebinars( - [FromQuery] XQuery query - ); - - /// - /// Query Owned Webinars ... - /// - /// - /// - Task>> QueryOwnedWebinars( - [FromQuery] XQuery query - ); - - /// - /// Query Joinable Webinars ... - /// - /// - /// - Task>> QueryJoinableWebinars( - [FromQuery] XQuery query - ); - - /// - /// Remove Specified Webinar ... - /// - /// - /// - Task> RemoveWebinar( - [FromRoute] Guid id - ); - #endregion - - // - #region WebinarSubscriber ... - /// - /// Subscribe a User to Webinar ... - /// - /// - /// - /// - Task> Subscribe( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ); - - /// - /// Check Specified User Subscribed on a Webinar or not ... - /// - /// - /// - /// - Task> IsSubscribed( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ); - - /// - /// Unsubscribe Specified User from a Specified Webinar ... - /// - /// - /// - /// - Task> Unsubscribe( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ); - - /// - /// Retrieve Specified Subscriber ... - /// - /// - /// - /// - Task> GetSubscriber( - [FromRoute] Guid id, - [FromRoute] string subscriberId - ); - - /// - /// Get all Specified Webinars Subscribers ... - /// - /// - /// - Task>> GetSubscribers( - [FromRoute] Guid id - ); - - /// - /// Query Specified Webinar's Subscribers ... - /// - /// - /// - /// - Task>> QuerySubscribers( - [FromRoute] Guid id, - [FromQuery] XQuery query - ); - #endregion - - // - #region File Actions ... - /// - /// Upload Specified Files for Specified Webinar ... - /// - /// - /// - /// - Task>> UploadFiles( - [FromRoute] Guid id, - [FromForm] IFormFileCollection files - ); - - /// - /// Retrieve Specified Webinar's Files ... - /// - /// - /// - Task>> GetFiles( - [FromRoute] Guid id - ); - - /// - /// Stream Specified File of Specified Webinar ... - /// - /// - /// - /// - Task StreamFile( - [FromRoute] Guid id, - [FromRoute] Guid fileId - ); - - /// - /// Download Specified File of Specified Webinar ... - /// - /// - /// - /// - Task DownloadFile( - [FromRoute] Guid id, - [FromRoute] Guid fileId - ); - - /// - /// Attach Provided Files to Specified Webinar ... - /// - /// - /// - /// - [HttpPost("{id}/Files/AttachMany")] - Task AttachFiles( - [FromRoute] Guid id, - [FromQuery] string ids - ); - - /// - /// Detach Provided Files to Specified Webinar ... - /// - /// - /// if null, detach all files ... - /// - [HttpDelete("{id}/Files/DetachMany")] - Task DetachFiles( - [FromRoute] Guid id, - [FromQuery] string ids = null - ); - #endregion - - // - #region Tags Actions ... - /// - /// Attach Specified Tags To Specified Webinar ... - /// - /// - /// - /// - Task AttachTags( - [FromRoute] Guid id, - [FromQuery] string tags - ); - - /// - /// Detach Specified Tags From Specified Webinar ... - /// - /// - /// if null, remove all attached tags ... - /// - Task DetachTags( - [FromRoute] Guid id, - [FromQuery] string tags - ); - - /// - /// Retrieve Specified Webinars Tags ... - /// - /// - /// - Task>> GetTags( - [FromRoute] Guid id - ); - #endregion - } -} \ No newline at end of file diff --git a/Interfaces/IXWebinarSubscriberSeeder.cs b/Interfaces/IXWebinarSubscriberSeeder.cs new file mode 100644 index 0000000..12387e1 --- /dev/null +++ b/Interfaces/IXWebinarSubscriberSeeder.cs @@ -0,0 +1,8 @@ +using xDataService.Interfaces; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Interfaces +{ + public interface IXWebinarSubscriberSeeder : IXBaseDbSeeder + { } +} \ No newline at end of file diff --git a/Interfaces/IXWebinarTagProvider.cs b/Interfaces/IXWebinarTagProvider.cs deleted file mode 100644 index 47c8a16..0000000 --- a/Interfaces/IXWebinarTagProvider.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using xTagService.Interfaces; - -namespace xWebinarService.Interfaces -{ - public interface IXWebinarTagProvider : IXBaseTagProvider - { } -} \ No newline at end of file diff --git a/Interfaces/IXWebinarTitleResourceProvider.cs b/Interfaces/IXWebinarTitleResourceProvider.cs deleted file mode 100644 index a112d22..0000000 --- a/Interfaces/IXWebinarTitleResourceProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -using xStringService.Interfaces; - -namespace xWebinarService.Interfaces -{ - public interface IXWebinarTitleResourceProvider : IXBaseStringResourceProvider - { } -} \ No newline at end of file diff --git a/Models/Dtos/XWebinarDto.cs b/Models/Dtos/XWebinarDto.cs index 17b2541..5d6c559 100644 --- a/Models/Dtos/XWebinarDto.cs +++ b/Models/Dtos/XWebinarDto.cs @@ -5,24 +5,14 @@ using xWebinarService.Constants; namespace xWebinarService.Models.Dtos { - public class XWebinarDto : XBaseDto + public class XWebinarDto : XBaseGuidIDEntityDto { - public Guid Id { get; set; } - public XResourceDto Title { get; set; } - public XResourceDto Description { get; set; } + public bool Enabled { get; set; } public string OwnerId { get; set; } public XPersonDto Owner { get; set; } public XWebinarType Type { get; set; } + public XResourceDto Title { get; set; } public DateTime CreatedOn { get; set; } - public bool Enabled { get; set; } - } - - public class XWebinarSubscriberDto : XBaseDto - { - public int Id { get; set; } - public Guid WebinarId { get; set; } - public string SubscriberId { get; set; } - public XPersonDto Subscriber { get; set; } - public DateTime SubscribedOn { get; set; } + public XResourceDto Description { get; set; } } } \ No newline at end of file diff --git a/Models/Dtos/XWebinarSubscriberDto.cs b/Models/Dtos/XWebinarSubscriberDto.cs new file mode 100644 index 0000000..8b97a8b --- /dev/null +++ b/Models/Dtos/XWebinarSubscriberDto.cs @@ -0,0 +1,14 @@ +using System; +using xModels.Base; +using xModels.Dtos; + +namespace xWebinarService.Models.Dtos +{ + public class XWebinarSubscriberDto : XBaseIntIDEntityDto + { + public Guid WebinarId { get; set; } + public string SubscriberId { get; set; } + public XPersonDto Subscriber { get; set; } + public DateTime SubscribedOn { get; set; } + } +} \ No newline at end of file diff --git a/Models/Entities/XWebinar.cs b/Models/Entities/XWebinar.cs index b98fc9e..e6fba67 100644 --- a/Models/Entities/XWebinar.cs +++ b/Models/Entities/XWebinar.cs @@ -49,18 +49,6 @@ namespace xWebinarService.Models.Entities /// Specified Webinar Enabled or not ... /// /// - public bool Enabled { get; set; } - } - - /// - /// Webinar Subscriber ... - /// - public class XWebinarSubscriber : XBaseIntIDEntity - { - [Required] - public string SubscriberId { get; set; } - [Required] - public Guid WebinarId { get; set; } - public DateTime SubscribedOn { get; set; } + public bool Enabled { get; set; } } } \ No newline at end of file diff --git a/Models/Entities/XWebinarGroupEntity.cs b/Models/Entities/XWebinarGroupEntity.cs deleted file mode 100644 index f6f3cc5..0000000 --- a/Models/Entities/XWebinarGroupEntity.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using xModels.Base; -using xPushService.Base; - -namespace xWebinarService.Models.Entities -{ - public class XWebinarGroupEntity : XBaseGuidIDEntity - { - public Guid WebinarId { get; set; } - public List Connections { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/Models/Entities/XWebinarSubscriber.cs b/Models/Entities/XWebinarSubscriber.cs new file mode 100644 index 0000000..6fb7544 --- /dev/null +++ b/Models/Entities/XWebinarSubscriber.cs @@ -0,0 +1,20 @@ +using System; +using System.ComponentModel.DataAnnotations; +using xModels.Base; + +namespace xWebinarService.Models.Entities +{ + /// + /// Webinar Subscriber ... + /// + public class XWebinarSubscriber : XBaseIntIDEntity + { + [Required] + public string SubscriberId { get; set; } + + [Required] + public Guid WebinarId { get; set; } + + public DateTime SubscribedOn { get; set; } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XWebinarDtoHub.cs b/Providers/Dtos/XWebinarDtoHub.cs new file mode 100644 index 0000000..c6b4353 --- /dev/null +++ b/Providers/Dtos/XWebinarDtoHub.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Extensions.Logging; +using xPushService.Base; +using xWebinarService.Interfaces.Dtos; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Dtos +{ + public class XWebinarDtoHub : XBaseDtoHub, IXWebinarDtoHub + { + public XWebinarDtoHub( + ILogger logger + ) : base(logger) + { } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XWebinarRepositoryService.cs b/Providers/Dtos/XWebinarRepositoryService.cs new file mode 100644 index 0000000..a07cc27 --- /dev/null +++ b/Providers/Dtos/XWebinarRepositoryService.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using AutoMapper; +using xDataService.Providers; +using xWebinarService.Interfaces.Dtos; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Dtos +{ + public class XWebinarRepositoryService : XBaseRepositoryService, IXWebinarRepositoryService + { + public XWebinarRepositoryService( + IXWebinarRepository repository, + IEnumerable mapperProfiles = null + ) : base( + repository, + mapperProfiles + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XWebinarServiceProvider.cs b/Providers/Dtos/XWebinarServiceProvider.cs new file mode 100644 index 0000000..d6cd18f --- /dev/null +++ b/Providers/Dtos/XWebinarServiceProvider.cs @@ -0,0 +1,27 @@ +using System; +using Microsoft.AspNetCore.SignalR; +using xDataService.Configuration; +using xIdentityService.Interfaces; +using xPushService.Base; +using xWebinarService.Interfaces.Dtos; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Dtos +{ + public class XWebinarServiceProvider : XBaseDtoProvider, IXWebinarServiceProvider + { + public XWebinarServiceProvider( + IHubContext hub, + XDataServiceConfiguration dataConfiguration, + IXWebinarRepositoryService service, + IXIdentityProvider identityProvider = null + ) : base( + hub, + dataConfiguration, + service, + identityProvider + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XWebinarSubscriberDtoHub.cs b/Providers/Dtos/XWebinarSubscriberDtoHub.cs new file mode 100644 index 0000000..526f1b4 --- /dev/null +++ b/Providers/Dtos/XWebinarSubscriberDtoHub.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.Logging; +using xPushService.Base; +using xWebinarService.Interfaces.Dtos; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Dtos +{ + public class XWebinarSubscriberDtoHub : XBaseDtoHub, IXWebinarSubscriberDtoHub + { + public XWebinarSubscriberDtoHub( + ILogger logger + ) : base(logger) + { } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XWebinarSubscriberRepositoryService.cs b/Providers/Dtos/XWebinarSubscriberRepositoryService.cs new file mode 100644 index 0000000..741f481 --- /dev/null +++ b/Providers/Dtos/XWebinarSubscriberRepositoryService.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using AutoMapper; +using xDataService.Providers; +using xWebinarService.Interfaces.Dtos; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Dtos +{ + public class XWebinarSubscriberRepositoryService : XBaseRepositoryService, IXWebinarSubscriberRepositoryService + { + public XWebinarSubscriberRepositoryService( + IXWebinarSubscriberRepository repository, + IEnumerable mapperProfiles = null + ) : base( + repository, + mapperProfiles + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Dtos/XWebinarSubscriberServiceProvider.cs b/Providers/Dtos/XWebinarSubscriberServiceProvider.cs new file mode 100644 index 0000000..ea22e4a --- /dev/null +++ b/Providers/Dtos/XWebinarSubscriberServiceProvider.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.SignalR; +using xDataService.Configuration; +using xIdentityService.Interfaces; +using xPushService.Base; +using xWebinarService.Interfaces.Dtos; +using xWebinarService.Models.Dtos; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Dtos +{ + public class XWebinarSubscriberServiceProvider : XBaseDtoProvider, IXWebinarSubscriberServiceProvider + { + public XWebinarSubscriberServiceProvider( + IHubContext hub, + XDataServiceConfiguration dataConfiguration, + IXWebinarSubscriberRepositoryService service, + IXIdentityProvider identityProvider = null + ) : base( + hub, + dataConfiguration, + service, + identityProvider + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarEFRepository.cs b/Providers/Entities/XWebinarEFRepository.cs new file mode 100644 index 0000000..bd7e75c --- /dev/null +++ b/Providers/Entities/XWebinarEFRepository.cs @@ -0,0 +1,27 @@ +using System; +using xDataService.Configuration; +using xDataService.Db; +using xDataService.Interfaces; +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarEFRepository : XBaseEFRepository, IXWebinarRepository + where TContext : XDbContext + { + public XWebinarEFRepository( + IXUnitOfWorks unitOfWorks, + XDataServiceConfiguration configuration, + IXWebinarKeyGenerator keyGenerator = null, + IXWebinarRepositoryEvents baseRepositoryEvents = null + ) : base( + unitOfWorks, + configuration, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarEntityHub.cs b/Providers/Entities/XWebinarEntityHub.cs new file mode 100644 index 0000000..13c6878 --- /dev/null +++ b/Providers/Entities/XWebinarEntityHub.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Extensions.Logging; +using xPushService.Base; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarEntityHub : XBaseEntityHub, IXWebinarEntityHub + { + public XWebinarEntityHub( + ILogger logger + ) : base(logger) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarInMemoryRepository.cs b/Providers/Entities/XWebinarInMemoryRepository.cs new file mode 100644 index 0000000..d016d6a --- /dev/null +++ b/Providers/Entities/XWebinarInMemoryRepository.cs @@ -0,0 +1,22 @@ +using System; +using xDataService.Configuration; +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarInMemoryRepository : XBaseInMemoryRepository, IXWebinarRepository + { + public XWebinarInMemoryRepository( + XDataServiceConfiguration configuration, + IXWebinarKeyGenerator keyGenerator = null, + IXWebinarRepositoryEvents baseRepositoryEvents = null + ) : base( + configuration, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarKeyGenerator.cs b/Providers/Entities/XWebinarKeyGenerator.cs new file mode 100644 index 0000000..b629a5d --- /dev/null +++ b/Providers/Entities/XWebinarKeyGenerator.cs @@ -0,0 +1,9 @@ +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarKeyGenerator : XGuidKeyGenerator, IXWebinarKeyGenerator + { } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarMongoRepository.cs b/Providers/Entities/XWebinarMongoRepository.cs new file mode 100644 index 0000000..3fd0d24 --- /dev/null +++ b/Providers/Entities/XWebinarMongoRepository.cs @@ -0,0 +1,26 @@ +using System; +using xDataService.Configuration; +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarMongoRepository : XBaseMongoRepository, IXWebinarRepository + { + public XWebinarMongoRepository( + XDataBaseConfiguration dbConfiguration, + XDataServiceConfiguration configuration, + string collectionName = null, + IXWebinarKeyGenerator keyGenerator = null, + IXWebinarRepositoryEvents baseRepositoryEvents = null + ) : base( + dbConfiguration, + configuration, + collectionName, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarRepositoryEvents.cs b/Providers/Entities/XWebinarRepositoryEvents.cs new file mode 100644 index 0000000..c9de261 --- /dev/null +++ b/Providers/Entities/XWebinarRepositoryEvents.cs @@ -0,0 +1,9 @@ +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarRepositoryEvents : XBaseRepositoryEvents, IXWebinarRepositoryEvents + { } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarRepositoryProvider.cs b/Providers/Entities/XWebinarRepositoryProvider.cs new file mode 100644 index 0000000..4da3ca5 --- /dev/null +++ b/Providers/Entities/XWebinarRepositoryProvider.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.AspNetCore.SignalR; +using xDataService.Configuration; +using xIdentityService.Interfaces; +using xPushService.Base; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarRepositoryProvider : XBaseEntityProvider, IXWebinarRepositoryProvider + { + public XWebinarRepositoryProvider( + IHubContext hub, + IXWebinarRepository repository, + XDataServiceConfiguration dataConfiguration, + IXIdentityProvider identityProvider = null + ) : base( + hub, + repository, + dataConfiguration, + identityProvider + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberEFRepository.cs b/Providers/Entities/XWebinarSubscriberEFRepository.cs new file mode 100644 index 0000000..3d13b75 --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberEFRepository.cs @@ -0,0 +1,26 @@ +using xDataService.Configuration; +using xDataService.Db; +using xDataService.Interfaces; +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberEFRepository : XBaseEFRepository, IXWebinarSubscriberRepository + where TContext : XDbContext + { + public XWebinarSubscriberEFRepository( + IXUnitOfWorks unitOfWorks, + XDataServiceConfiguration configuration, + IXWebinarSubscriberKeyGenerator keyGenerator = null, + IXWebinarSubscriberRepositoryEvents baseRepositoryEvents = null + ) : base( + unitOfWorks, + configuration, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberEntityHub.cs b/Providers/Entities/XWebinarSubscriberEntityHub.cs new file mode 100644 index 0000000..8d5841e --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberEntityHub.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.Logging; +using xPushService.Base; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberEntityHub : XBaseEntityHub, IXWebinarSubscriberEntityHub + { + public XWebinarSubscriberEntityHub( + ILogger logger + ) : base(logger) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberInMemoryRepository.cs b/Providers/Entities/XWebinarSubscriberInMemoryRepository.cs new file mode 100644 index 0000000..32eab1e --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberInMemoryRepository.cs @@ -0,0 +1,21 @@ +using xDataService.Configuration; +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberInMemoryRepository : XBaseInMemoryRepository, IXWebinarSubscriberRepository + { + public XWebinarSubscriberInMemoryRepository( + XDataServiceConfiguration configuration, + IXWebinarSubscriberKeyGenerator keyGenerator = null, + IXWebinarSubscriberRepositoryEvents baseRepositoryEvents = null + ) : base( + configuration, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberKeyGenerator.cs b/Providers/Entities/XWebinarSubscriberKeyGenerator.cs new file mode 100644 index 0000000..359f41b --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberKeyGenerator.cs @@ -0,0 +1,9 @@ +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberKeyGenerator : XIntKeyGenerator, IXWebinarSubscriberKeyGenerator + { } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberMongoRepository.cs b/Providers/Entities/XWebinarSubscriberMongoRepository.cs new file mode 100644 index 0000000..4935fe3 --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberMongoRepository.cs @@ -0,0 +1,25 @@ +using xDataService.Configuration; +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberMongoRepository : XBaseMongoRepository, IXWebinarSubscriberRepository + { + public XWebinarSubscriberMongoRepository( + XDataBaseConfiguration dbConfiguration, + XDataServiceConfiguration configuration, + string collectionName = null, + IXWebinarSubscriberKeyGenerator keyGenerator = null, + IXWebinarSubscriberRepositoryEvents baseRepositoryEvents = null + ) : base( + dbConfiguration, + configuration, + collectionName, + keyGenerator, + baseRepositoryEvents + ) + { } + } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberRepositoryEvents.cs b/Providers/Entities/XWebinarSubscriberRepositoryEvents.cs new file mode 100644 index 0000000..646e6fb --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberRepositoryEvents.cs @@ -0,0 +1,9 @@ +using xDataService.Providers; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberRepositoryEvents : XBaseRepositoryEvents, IXWebinarSubscriberRepositoryEvents + { } +} \ No newline at end of file diff --git a/Providers/Entities/XWebinarSubscriberRepositoryProvider.cs b/Providers/Entities/XWebinarSubscriberRepositoryProvider.cs new file mode 100644 index 0000000..a49c028 --- /dev/null +++ b/Providers/Entities/XWebinarSubscriberRepositoryProvider.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.AspNetCore.SignalR; +using xDataService.Configuration; +using xIdentityService.Interfaces; +using xPushService.Base; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers.Entities +{ + public class XWebinarSubscriberRepositoryProvider : XBaseEntityProvider, IXWebinarSubscriberRepositoryProvider + { + public XWebinarSubscriberRepositoryProvider( + IHubContext hub, + IXWebinarSubscriberRepository repository, + XDataServiceConfiguration dataConfiguration, + IXIdentityProvider identityProvider = null + ) : base( + hub, + repository, + dataConfiguration, + identityProvider + ) + { } + } +} \ No newline at end of file diff --git a/DataHelper/GraphQL/XWebinarGraphQLTypeHelper.cs b/Providers/GraphQL/XWebinarGraphQLTypeHelper.cs similarity index 93% rename from DataHelper/GraphQL/XWebinarGraphQLTypeHelper.cs rename to Providers/GraphQL/XWebinarGraphQLTypeHelper.cs index de01e92..09bf6ed 100644 --- a/DataHelper/GraphQL/XWebinarGraphQLTypeHelper.cs +++ b/Providers/GraphQL/XWebinarGraphQLTypeHelper.cs @@ -4,7 +4,7 @@ using xDataService.GraphQL; using xWebinarService.Interfaces.Entities; using xWebinarService.Models.Entities; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarGraphQLTypeHelper : XBaseGraphQLTypeHelper, IXWebinarGraphQLTypeHelper { diff --git a/DataHelper/GraphQL/XWebinarGraphQuery.cs b/Providers/GraphQL/XWebinarGraphQuery.cs similarity index 92% rename from DataHelper/GraphQL/XWebinarGraphQuery.cs rename to Providers/GraphQL/XWebinarGraphQuery.cs index fdb72c0..14ae8d3 100644 --- a/DataHelper/GraphQL/XWebinarGraphQuery.cs +++ b/Providers/GraphQL/XWebinarGraphQuery.cs @@ -5,7 +5,7 @@ using xDataService.GraphQL; using xWebinarService.Interfaces.Entities; using xWebinarService.Models.Entities; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarGraphQuery : XBaseGraphQLQuery { diff --git a/DataHelper/GraphQL/XWebinarGraphSchema.cs b/Providers/GraphQL/XWebinarGraphSchema.cs similarity index 86% rename from DataHelper/GraphQL/XWebinarGraphSchema.cs rename to Providers/GraphQL/XWebinarGraphSchema.cs index 668c110..29e47c8 100644 --- a/DataHelper/GraphQL/XWebinarGraphSchema.cs +++ b/Providers/GraphQL/XWebinarGraphSchema.cs @@ -1,7 +1,7 @@ using System; using GraphQL.Types; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarGraphSchema : Schema { diff --git a/DataHelper/GraphQL/XWebinarGraphType.cs b/Providers/GraphQL/XWebinarGraphType.cs similarity index 77% rename from DataHelper/GraphQL/XWebinarGraphType.cs rename to Providers/GraphQL/XWebinarGraphType.cs index 384f271..ed82ede 100644 --- a/DataHelper/GraphQL/XWebinarGraphType.cs +++ b/Providers/GraphQL/XWebinarGraphType.cs @@ -2,16 +2,18 @@ using System; using xDataService.GraphQL; using xWebinarService.Models.Entities; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarGraphType : XBaseGraphObjectType { public XWebinarGraphType() : base() { + Field(x => x.Type); Field(x => x.Title); - Field(x => x.Description); Field(x => x.OwnerId); + Field(x => x.Enabled); Field(x => x.CreatedOn); + Field(x => x.Description); } } } \ No newline at end of file diff --git a/DataHelper/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs b/Providers/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs similarity index 79% rename from DataHelper/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs rename to Providers/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs index 939c92f..92c35ba 100644 --- a/DataHelper/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs +++ b/Providers/GraphQL/XWebinarSubscriberGraphQLTypeHelper.cs @@ -1,20 +1,18 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using xDataService.Configuration; using xDataService.GraphQL; using xWebinarService.Interfaces.Entities; using xWebinarService.Models.Entities; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarSubscriberGraphQLTypeHelper : XBaseGraphQLTypeHelper, IXWebinarSubscriberGraphQLTypeHelper { public XWebinarSubscriberGraphQLTypeHelper( XDataServiceConfiguration configuration - ) : base(configuration) { } - + ) : base(configuration) + { } + public override string GetInQueryCollectionName() { return "webinarSubscribers"; diff --git a/DataHelper/GraphQL/XWebinarSubscriberGraphQuery.cs b/Providers/GraphQL/XWebinarSubscriberGraphQuery.cs similarity index 90% rename from DataHelper/GraphQL/XWebinarSubscriberGraphQuery.cs rename to Providers/GraphQL/XWebinarSubscriberGraphQuery.cs index 0323638..216c1e9 100644 --- a/DataHelper/GraphQL/XWebinarSubscriberGraphQuery.cs +++ b/Providers/GraphQL/XWebinarSubscriberGraphQuery.cs @@ -4,7 +4,7 @@ using xDataService.GraphQL; using xWebinarService.Interfaces.Entities; using xWebinarService.Models.Entities; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarSubscriberGraphQuery : XBaseGraphQLQuery { @@ -17,7 +17,6 @@ namespace xWebinarService.DataHelper.GraphQL repository, helper ) - { - } + { } } } \ No newline at end of file diff --git a/DataHelper/GraphQL/XWebinarSubscriberGraphSchema.cs b/Providers/GraphQL/XWebinarSubscriberGraphSchema.cs similarity index 87% rename from DataHelper/GraphQL/XWebinarSubscriberGraphSchema.cs rename to Providers/GraphQL/XWebinarSubscriberGraphSchema.cs index b4185da..533901f 100644 --- a/DataHelper/GraphQL/XWebinarSubscriberGraphSchema.cs +++ b/Providers/GraphQL/XWebinarSubscriberGraphSchema.cs @@ -1,7 +1,7 @@ using System; using GraphQL.Types; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarSubscriberGraphSchema : Schema { diff --git a/DataHelper/GraphQL/XWebinarSubscriberGraphType.cs b/Providers/GraphQL/XWebinarSubscriberGraphType.cs similarity index 89% rename from DataHelper/GraphQL/XWebinarSubscriberGraphType.cs rename to Providers/GraphQL/XWebinarSubscriberGraphType.cs index 6a780fc..866ecd7 100644 --- a/DataHelper/GraphQL/XWebinarSubscriberGraphType.cs +++ b/Providers/GraphQL/XWebinarSubscriberGraphType.cs @@ -1,15 +1,15 @@ using xDataService.GraphQL; using xWebinarService.Models.Entities; -namespace xWebinarService.DataHelper.GraphQL +namespace xWebinarService.Providers.GraphQL { public class XWebinarSubscriberGraphType : XBaseGraphObjectType { public XWebinarSubscriberGraphType() : base() { - Field(x => x.SubscriberId); Field(x => x.WebinarId); Field(x => x.SubscribedOn); + Field(x => x.SubscriberId); } } } \ No newline at end of file diff --git a/Providers/XWebinarDescriptionResourceProvider.cs b/Providers/XWebinarDescriptionResourceProvider.cs deleted file mode 100644 index aad3fec..0000000 --- a/Providers/XWebinarDescriptionResourceProvider.cs +++ /dev/null @@ -1,23 +0,0 @@ -using xCommons.Configurations; -using xStringService.Base; -using xStringService.Interfaces; -using xWebinarService.Interfaces; - -namespace xWebinarService.Providers -{ - /// - /// a Servide to Provides Requirements for XWebinar Description Resources ... - /// - public class XWebinarDescriptionResourceProvider : XBaseStringResourceProvider, IXWebinarDescriptionResourceProvider - { - public XWebinarDescriptionResourceProvider( - IXStringProvider provider, - XAppConfiguration appConfiguration - ) : base( - "XWEBD", - provider, - appConfiguration - ) - { } - } -} \ No newline at end of file diff --git a/Providers/XWebinarEntityRegisterar.cs b/Providers/XWebinarEntityRegisterar.cs new file mode 100644 index 0000000..1370776 --- /dev/null +++ b/Providers/XWebinarEntityRegisterar.cs @@ -0,0 +1,35 @@ +using System; +using Microsoft.EntityFrameworkCore; +using xDataService.Interfaces; +using xDataService.Providers; +using xWebinarService.Configurations.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers +{ + public class XWebinarEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar + { + public XWebinarEntityRegisterar() + : base(nameof(XWebinarEntityRegisterar)) + { + // + // Add Entity ... + AddEntity(); + } + + /// + /// Configure Entities ... + /// + /// + public override void ConfigureEntities(ModelBuilder modelBuilder) + { + // + // Configure Entity Using Provided ... + modelBuilder + .ApplyConfigurationsFromAssembly(typeof(XWebinarEntityConfiguration).Assembly); + + // + base.ConfigureEntities(modelBuilder); + } + } +} \ No newline at end of file diff --git a/Providers/XWebinarFileProvider.cs b/Providers/XWebinarFileProvider.cs deleted file mode 100644 index 39adbc2..0000000 --- a/Providers/XWebinarFileProvider.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using xFileService.Interfaces; -using xFileService.Providers; -using xWebinarService.Interfaces; -using xWebinarService.Models.Entities; - -namespace xWebinarService.Providers -{ - public class XWebinarFileProvider : XBaseFileProvider, IXWebinarFileProvider - { - public XWebinarFileProvider( - IXFileProvider fileProvider - ) : base( - providedFor: nameof(XWebinar), - fileProvider: fileProvider - ) - { } - } -} \ No newline at end of file diff --git a/Providers/XWebinarGroupStore.cs b/Providers/XWebinarGroupStore.cs deleted file mode 100644 index 35c24d6..0000000 --- a/Providers/XWebinarGroupStore.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using xDataService.Configuration; -using xDataService.InMemRepositories; -using xDataService.Interfaces; -using xWebinarService.Interfaces; -using xWebinarService.Models.Entities; - -namespace xWebinarService.Providers -{ - public class XWebinarGroupStore : XBaseInMemoryRepositoy, IXWebinarGroupStore - { - public XWebinarGroupStore( - XDataServiceConfiguration configuration, - IXKeyGenerator keyGenerator = null, - IXBaseRepositoryEvents baseRepositoryEvents = null - ) : base(configuration, keyGenerator, baseRepositoryEvents) - { - } - } -} \ No newline at end of file diff --git a/Providers/XWebinarProvider.cs b/Providers/XWebinarProvider.cs deleted file mode 100644 index ea3cda3..0000000 --- a/Providers/XWebinarProvider.cs +++ /dev/null @@ -1,2214 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SignalR; -using MongoDB.Driver; -using xCommons.Extensions; -using xDataService.Configuration; -using xDataService.Extensions; -using xExceptions.Constants; -using xIdentityModels.Dtos; -using xIdentityModels.Models; -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; -using xWebinarService.Interfaces.Entities; -using xWebinarService.Models.Dtos; -using xWebinarService.Models.Entities; -using XFileDto = xFileService.Models.Dtos.XFileDto; - -namespace xWebinarService.Providers -{ - /// - /// Implement all Webinar Related Things here ... - /// - public class XWebinarProvider : IXWebinarProvider - { - // - #region Props ... - public IHubContext Hub { get; } - public IXIdentityProvider IdentityProvider { get; } - public IXWebinarRepository WebinarRepository { get; } - public IXWebinarTagProvider WebinarTagProvider { get; } - public IXWebinarFileProvider WebinarFileProvider { get; } - public XDataServiceConfiguration DataSercviceConfiguration { get; } - public IXWebinarTitleResourceProvider TitleResourceProvider { get; } - public IXWebinarSubscriberRepository WebinarSubscriberRepository { get; } - public IXWebinarDescriptionResourceProvider DescriptionResourceProvider { get; } - #endregion - - // - #region Constructor ... - public XWebinarProvider( - IXIdentityProvider identityProvider, - IXWebinarRepository webinarRepository, - IXWebinarTagProvider webinarTagProvider, - IXWebinarFileProvider webinarFileProvider, - XDataServiceConfiguration dataSercviceConfiguration, - IXWebinarTitleResourceProvider titleResourceProvider, - IXWebinarSubscriberRepository webinarSubscriberRepository, - IXWebinarDescriptionResourceProvider descriptionResourceProvider, - IHubContext hub = null - ) - { - // - Hub = hub; - IdentityProvider = identityProvider; - WebinarRepository = webinarRepository; - WebinarTagProvider = webinarTagProvider; - WebinarFileProvider = webinarFileProvider; - TitleResourceProvider = titleResourceProvider; - DataSercviceConfiguration = dataSercviceConfiguration; - WebinarSubscriberRepository = webinarSubscriberRepository; - DescriptionResourceProvider = descriptionResourceProvider; - } - #endregion - - // - #region Tools ... - /// - /// Converts Specified XWebinar Entity to it's Corresponding Dto Presentation - /// and also Fill Owner and Title/Description Resources ... - /// - /// - /// - public async Task ToXWebinarDto(XWebinar model) - { - // - // Validate ... - bool isValid = - !model.IsNullOrDefault() && - !model.Title.IsNullOrEmpty() && - !model.OwnerId.IsNullOrEmpty() && - !model.Description.IsNullOrEmpty(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - var result = new XWebinarDto - { - // - // Set Common Properties ... - Id = model.Id, - Type = model.Type, - OwnerId = model.OwnerId, - Enabled = model.Enabled, - CreatedOn = model.CreatedOn, - - // - // Fill Resources ... - Title = await TitleResourceProvider.GetResource(model.Id.ToString()), - Description = await DescriptionResourceProvider.GetResource(model.Id.ToString()) - }; - - // - // Prepare Inner API Providers Device Dto ... - var device = IdentityProvider.GetDevice(); - var userInfo = await IdentityProvider.GetUserInfo( - device: device, - userSelectByParam: model.OwnerId - ); - isValid = !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - result.Owner = userInfo.ToXPersonDto(); - - // - return result; - } - - /// - /// Converts Specified WebinarSubscriber Entity to it's Dto Presentation ... - /// - /// - /// - public async Task ToXWebinarSubscriberDto(XWebinarSubscriber model) - { - // - bool isValid = - !model.IsNull() && - !model.SubscriberId.IsNullOrEmpty(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Retrieve User Info ... - var device = IdentityProvider.GetDevice(); - var userInfo = await IdentityProvider.GetUserInfo( - device: device, - userSelectByParam: model.SubscriberId - ); - isValid = !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - var result = new XWebinarSubscriberDto - { - Id = model.Id, - WebinarId = model.WebinarId, - SubscriberId = model.SubscriberId, - SubscribedOn = model.SubscribedOn, - Subscriber = userInfo.ToXPersonDto(), - }; - - // - return result; - } - #endregion - - // - #region Actions ... - /// - /// Create Webinar ... - /// - /// - /// - /// - /// - /// - /// - public async Task CreateWebinar( - XWebinarDto item, - IEnumerable tags = null, - IFormFileCollection files = null, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ) - { - // - // Validate ... - bool isValid = - !item.IsNull() && - !item.Title.IsNull() && - !item.Description.IsNull() && - !userInfo.IsNullOrDefault() && - !item.OwnerId.IsNullOrEmpty() && - userInfo.UserId == item.OwnerId; - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Title and Descriptions Has Value ... - isValid = - item.Title.Locales.HasChild() && - item.Description.Locales.HasChild() && - item.Title.Locales.All(l => !l.Value.IsNullOrEmpty()) && - item.Description.Locales.All(l => !l.Value.IsNullOrEmpty()); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Prepare Temp Webinar Entity ... - string tmpValue = Guid.NewGuid().ToString(); - var entity = new XWebinar - { - Type = item.Type, - OwnerId = item.OwnerId, - Title = "T_" + tmpValue, - CreatedOn = DateTime.UtcNow, - Description = "D_" + tmpValue, - }; - entity = await WebinarRepository.AddAsync(entity); - isValid = - !entity.IsNullOrDefault() && - !entity.Id.IsDefaultGuid(); - if (!isValid) - { - XException.ActionFailed.Throw(); - } - - // - // Use Entity ID as Resources Suffix ... - Guid suffixGuid = entity.Id; - string suffix = suffixGuid.ToString(); - var titleResource = await TitleResourceProvider.AddResource( - suffix: suffix, - item: item.Title - ); - var descriptionResource = await DescriptionResourceProvider.AddResource( - suffix: suffix, - item: item.Description - ); - isValid = - // - // Title Resource Validation ... - !titleResource.IsNullOrDefault() && - titleResource.Locales.HasChild() && - !titleResource.Resource.IsNullOrEmpty() && - // - // Description Resource Validation ... - !descriptionResource.IsNullOrDefault() && - descriptionResource.Locales.HasChild() && - !descriptionResource.Resource.IsNullOrEmpty() - ; - if (!isValid) - { - // - // Rollback ... - try - { - // - entity.Id = suffixGuid; - await TitleResourceProvider.Remove(suffix); - await WebinarRepository.RemoveAsync(entity); - await DescriptionResourceProvider.Remove(suffix); - } - catch { } - - // - XException.ActionFailed.Throw(); - } - - // - // Update Title/Description Resources ... - entity.Title = titleResource.Resource; - entity.Description = descriptionResource.Resource; - entity = await WebinarRepository.UpdateAsync(entity.Id, entity); - isValid = !entity.IsNullOrDefault(); - if (!isValid) - { - // - // Rollback ... - try - { - // - entity.Id = suffixGuid; - await TitleResourceProvider.Remove(suffix); - await WebinarRepository.RemoveAsync(entity); - await DescriptionResourceProvider.Remove(suffix); - } - catch { } - - // - XException.ActionFailed.Throw(); - } - - // - // Check For Files ... - isValid = !files.IsNull() && files.Count() > 0; - if (isValid) - { - // - try - { - // - await UploadFiles( - id: entity.Id, - files: files, - userInfo: userInfo - ); - } - catch { } - } - - // - // Check For Tags ... - isValid = !tags.IsNull() && tags.HasChild(); - if (isValid) - { - // - try - { - // - await AttachTags( - id: entity.Id, - userInfo: userInfo, - forceAttachToFiles: true, - tags: tags.ToListString(), - connectionId: connectionId - ); - } - catch { } - } - - // - await SendPush( - action: XBaseEntityHubAction.Add.GetStringValue(), - payLoad: entity.ToJSON(camelCase: true), - connectionId: connectionId - ); - - // - // Convert Entity to Dto ... - var result = await ToXWebinarDto(entity); - return result; - } - - /// - /// Update a Webinar ... - /// - /// - /// - /// - /// - public async Task UpdateWebinar( - XWebinarDto item, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ) - { - // - // Since Medias and Tags Manages Separatly, here - // we dont need to ensure that ... - - // - // Validate ... - bool isValid = - !item.Id.IsNull() && - !item.IsNullOrDefault() && - !item.Id.IsDefaultGuid() && - !userInfo.IsNullOrDefault() && - !item.OwnerId.IsNullOrEmpty() && - !item.Title.IsNullOrDefault() && - !item.Description.IsNullOrDefault() && - // - // Title Validation ... - item.Title.Locales.HasChild() && - !item.Title.Resource.IsNullOrEmpty() && - item.Title.Locales.All(l => !l.IsNullOrDefault() && !l.Value.IsNullOrEmpty() && !l.Language.IsNullOrEmpty()) && - // - // Description Validation ... - item.Description.Locales.HasChild() && - !item.Description.Resource.IsNullOrEmpty() && - item.Description.Locales.All(l => !l.IsNullOrDefault() && !l.Value.IsNullOrEmpty() && !l.Language.IsNullOrEmpty()) - ; - if (!isValid) - { - 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); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - // Retrieve Entity ... - var entity = await WebinarRepository.GetAsync(item.Id); - - // - // Check if Type Change Update it ... - if (entity.Type != item.Type) - { - // - entity.Type = item.Type; - entity = await WebinarRepository.UpdateAsync(entity.Id, entity); - } - - // - // Check if Enabled Change Update it ... - if (entity.Enabled != item.Enabled) - { - // - entity.Enabled = item.Enabled; - entity = await WebinarRepository.UpdateAsync(entity.Id, entity); - } - - // - // Retrieve Entity Dto ... - var entityDto = await ToXWebinarDto(entity); - - // - // Exclude Must Remove items ... - var mustRemoveTitleLocals = entityDto.Title.Locales.Where(e => - !item.Title.Locales.Any(l => - l.Language.ToNormalString() == e.Language.ToNormalString()) - ); - var mustRemoveDescriptionLocals = entityDto.Description.Locales.Where(e => - !item.Description.Locales.Any(l => - l.Language.ToNormalString() == e.Language.ToNormalString()) - ); - - // - // Remove Specified Locales ... - - // - // Titles ... - foreach (var locale in mustRemoveTitleLocals) - { - // - try - { - // - await TitleResourceProvider.Remove( - resource: entity.Title, - language: locale.Language - ); - } - catch { } - } - - // - // Descriptions ... - foreach (var locale in mustRemoveDescriptionLocals) - { - // - try - { - // - await DescriptionResourceProvider.Remove( - resource: entity.Description, - language: locale.Language - ); - } - catch { } - } - - // - // Add Or Update Locales ... - - // - // Title ... - var titleAddedLocales = await TitleResourceProvider.AddOrUpdate( - resource: entity.Title, - locales: item.Title.Locales - ); - - // - // Description ... - var descriptionAddedLocales = await DescriptionResourceProvider.AddOrUpdate( - resource: entity.Description, - locales: item.Description.Locales - ); - - // - entity = await WebinarRepository.GetAsync(entity.Id); - var result = await ToXWebinarDto(entity); - - // - if (!result.IsNullOrDefault()) - { - // - await SendPush( - action: XBaseEntityHubAction.Update.GetStringValue(), - payLoad: entity.ToJSON(camelCase: true), - connectionId: connectionId - ); - } - - // - return result; - } - - /// - /// Retrieve Specified Webinar ... - /// - /// - /// - public async Task GetWebinar(Guid id) - { - // - var entity = await WebinarRepository.GetAsync(id); - if (entity.IsNullOrDefault()) - { - XException.NotFound.Throw(); - } - - // - var result = await ToXWebinarDto(entity); - return result; - } - - /// - /// Retrieve all Exists Webinars ... - /// - /// - public async Task> GetWebinars() - { - // - var entities = WebinarRepository - .AsQueryable() - .ToList(); - - // - var result = new List(); - if (!entities.IsNull() && entities.HasChild()) - { - // - foreach (var entity in entities) - { - // - var dto = await ToXWebinarDto(entity); - if (!dto.IsNullOrDefault()) - { - result.Add(dto); - } - } - } - - // - return result; - } - - /// - /// Query Webinars ... - /// - /// - /// - public async Task> QueryWebinars(XQuery query) - { - // - // Validate ... - if (query.IsNull()) - { - XException.InvalidArgs.Throw(); - } - - // - // Normalize ... - query = query.NormalizeQuery(DataSercviceConfiguration); - - // - // Since in Resourceable Entities we have to Search on Locales - // we Must Implement Senario Custom ... - var totalEntities = await WebinarRepository.GetAllAsync(); - - // - var list = new List(); - foreach (var entity in totalEntities) - { - // - var dto = await ToXWebinarDto(entity); - list.Add(dto); - } - var items = list.AsEnumerable(); - var totalItemsCount = items.Count(); - - // - // Apply Filter ... - if (!query.Filter.IsNullOrEmpty()) - { - // - items = items - .ApplyFilter(query.Filter); - } - int filteredItemsCount = items.Count(); - - // - // Count Pages ... - var totalPagesCount = query.CountPages(totalItemsCount); - var filteredPagesCount = query.CountPages(filteredItemsCount); - - // - // Apply Paging and Sorting ... - if (totalItemsCount > 0 && - filteredItemsCount > 0) - { - // - // Apply Sorting ... - items = items - .ToList() - .ApplySorting( - query.SortBy, - query.IsAscending - ); - - // - // Apply Paging ... - items = items - .ToList() - .ApplyPaging( - query.Page, - query.PageSize - ); - } - - // - // Prepare Result ... - var result = new XQueryResult - { - Page = query.Page, - Items = items.ToList(), - PageSize = query.PageSize, - TotalPages = totalPagesCount, - TotalItems = totalItemsCount, - TotalFilteredPages = filteredPagesCount, - TotalFilteredItems = filteredItemsCount - }; - - // - return result; - } - - /// - /// Conditional Query Webinars ... - /// - /// - /// - /// - public async Task> ConditionalQueryWebinars( - Expression> whereClause, - XQuery query - ) - { - // - // Validate ... - if (query.IsNull() || whereClause.IsNull()) - { - XException.InvalidArgs.Throw(); - } - - // - // Normalize ... - query = query.NormalizeQuery(DataSercviceConfiguration); - - // - // Compile Expression ... - var whereFunc = whereClause.Compile(); - - // - // Since in Resourceable Entities we have to Search on Locales - // we Must Implement Senario Custom ... - var totalEntities = await WebinarRepository.GetAllAsync(); - - // - var list = new List(); - foreach (var entity in totalEntities) - { - // - var dto = await ToXWebinarDto(entity); - - // - // Validate and Check Conditions ... - if (!dto.IsNullOrDefault() && whereFunc(dto)) - { - list.Add(dto); - } - } - var items = list.AsEnumerable(); - var totalItemsCount = items.Count(); - - // - // Apply Filter ... - if (!query.Filter.IsNullOrEmpty()) - { - // - items = items - .ApplyFilter(query.Filter); - } - int filteredItemsCount = items.Count(); - - // - // Count Pages ... - var totalPagesCount = query.CountPages(totalItemsCount); - var filteredPagesCount = query.CountPages(filteredItemsCount); - - // - // Apply Paging and Sorting ... - if (totalItemsCount > 0 && - filteredItemsCount > 0) - { - // - // Apply Sorting ... - items = items - .ToList() - .ApplySorting( - query.SortBy, - query.IsAscending - ); - - // - // Apply Paging ... - items = items - .ToList() - .ApplyPaging( - query.Page, - query.PageSize - ); - } - - // - // Prepare Result ... - var result = new XQueryResult - { - Page = query.Page, - Items = items.ToList(), - PageSize = query.PageSize, - TotalPages = totalPagesCount, - TotalItems = totalItemsCount, - TotalFilteredPages = filteredPagesCount, - TotalFilteredItems = filteredItemsCount - }; - - // - return result; - } - - /// - /// Query Owned Webinars ... - /// - /// - /// - public async Task> QueryOwnedWebinars( - XQuery query, - XUserClaimsInfoDto userInfo = null - ) - { - // - // Validate ... - var isValid = !query.IsNullOrDefault() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - Expression> whereClause = d => d.OwnerId == userInfo.UserId; - var result = await ConditionalQueryWebinars( - query: query, - whereClause: whereClause - ); - return result; - } - - /// - /// Query Joinable Webinars ... - /// - /// - /// - public async Task> QueryJoinableWebinars( - XQuery query, - XUserClaimsInfoDto userInfo = null - ) - { - // - // Validate ... - var isValid = !query.IsNullOrDefault() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Create an Expression to Check Specified Webinar is Joinable by Provided User Info or not ... - Expression> whereClause = d => - d.OwnerId == userInfo.UserId || - d.Type == XWebinarType.Public || - WebinarSubscriberRepository.AsQueryable().Any(ws => ws.WebinarId == d.Id && ws.SubscriberId == userInfo.UserId); - var result = await ConditionalQueryWebinars( - query: query, - whereClause: whereClause - ); - return result; - } - - /// - /// Remove Specified Webinar ... - /// - /// - /// - /// - /// - public async Task RemoveWebinar( - Guid webinarId, - XUserClaimsInfoDto userInfo = null, - string connectionId = null - ) - { - // - bool result = false; - - // - // Validate ... - result = - !webinarId.IsNull() && - !webinarId.IsDefaultGuid(); - if (!result) - { - return result; - } - - // - // Check Permissions ... - result = await HasPermission(webinarId, userInfo); - if (!result) - { - XException.NotAllowed.Throw(); - } - - // - // Get Entity ... - var entity = await WebinarRepository.GetAsync(webinarId); - result = !entity.IsNullOrDefault(); - if (!result) - { - return result; - } - - // - // Handle Remove ... - var subscribers = await GetSubscribers( - webinarId: webinarId, - userInfo: userInfo - ); - try - { - // - // Unsubscribe all Subscribers ... - await subscribers.SelectAsync(async s => await Unsubscribe( - webinarId: webinarId, - subscriberId: s.SubscriberId - )); - - // - // Detach Tags ... - await DetachTags( - tags: null, // Pass Null to Detach All Referenced Tags ... - 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); - await DescriptionResourceProvider.Remove(resourceID); - - // - await WebinarRepository.RemoveAsync(webinarId); - } - catch { } - - // - // Check Entity Removed ... - result = !await WebinarRepository.IsExistsAsync(webinarId); - if (result) - { - // - await SendPush( - action: XBaseEntityHubAction.Delete.GetStringValue(), - payLoad: entity.ToJSON(camelCase: true), - connectionId: connectionId - ); - } - - // - return result; - } - #endregion - - // - #region WebinarSubscriber ... - /// - /// Subscribe a User to Webinar ... - /// - /// - /// - /// - /// - /// - public async Task Subscribe( - Guid webinarId, - string subscriberId, - string connectionId = null, - XUserClaimsInfoDto userInfo = null - ) - { - // - var result = false; - - // - // Validate ... - result = - !webinarId.IsNull() && - !webinarId.IsDefaultGuid() && - !subscriberId.IsNullOrEmpty() && - !userInfo.IsNullOrDefault(); - if (!result) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Webinar Exists ... - result = await WebinarRepository.IsExistsAsync(webinarId); - if (!result) - { - XException.NotFound.Throw(); - } - - // - // Retrieve Webinar Entity ... - var webinar = await WebinarRepository.GetAsync(webinarId); - result = !webinar.IsNullOrDefault(); - if (!result) - { - XException.ActionFailed.Throw(); - } - - // - // Check Permissions ... - result = - userInfo.UserId == webinar.OwnerId || - webinar.Type == XWebinarType.Public || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!result) - { - XException.NotAllowed.Throw(); - } - - // - // Check User Exists ... - var device = IdentityProvider.GetDevice(); - XOpenActionUserInfoDto subscriber = null; - try - { - // - subscriber = await IdentityProvider.GetUserInfo( - device: device, - userSelectByParam: subscriberId - ); - } - catch { } - result = !subscriber.IsNullOrDefault(); - if (!result) - { - XException.NotFound.Throw(); - } - - // - // Create Subscription Model ... - var entity = new XWebinarSubscriber - { - WebinarId = webinarId, - SubscriberId = subscriberId, - SubscribedOn = DateTime.UtcNow, - }; - entity = await WebinarSubscriberRepository.AddAsync(entity); - result = !entity.IsNullOrDefault(); - if (result) - { - // - await SendPush( - action: XWebinarEntityHubAction.Subscribe.GetStringValue(), - payLoad: entity.ToJSON(camelCase: true), - connectionId: connectionId - ); - } - - // - return result; - } - - /// - /// Check Specified User Subscribed on a Webinar or not ... - /// - /// - /// - /// - /// - public async Task IsSubscribed( - Guid webinarId, - string subscriberId, - XUserClaimsInfoDto userInfo = null - ) - { - // - bool result = false; - - // - // Validate ... - result = - !webinarId.IsNull() && - !webinarId.IsDefaultGuid() && - !userInfo.IsNullOrDefault() && - !subscriberId.IsNullOrEmpty(); - if (!result) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Webinar Exists ... - var webinar = await WebinarRepository.GetAsync(webinarId); - result = !webinar.IsNullOrDefault(); - if (!result) - { - XException.NotFound.Throw(); - } - - // - // Check Permission ... - result = - userInfo.UserId == subscriberId || - userInfo.UserId == webinar.OwnerId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!result) - { - XException.NotAllowed.Throw(); - } - - // - // Check User Exists ... - var device = IdentityProvider.GetDevice(); - XOpenActionUserInfoDto suscriber = null; - try - { - // - suscriber = await IdentityProvider.GetUserInfo( - device: device, - userSelectByParam: subscriberId - ); - } - catch { } - result = !suscriber.IsNullOrDefault(); - if (!result) - { - XException.NotFound.Throw(); - } - - // - result = !(await WebinarSubscriberRepository.FindOneAsync(ws => - ws.WebinarId == webinarId && - ws.SubscriberId == subscriberId - )).IsNull(); - - // - return result; - } - - /// - /// Unsubscribe Specified User from a Specified Webinar ... - /// - /// - /// - /// - /// - /// - public async Task Unsubscribe( - Guid webinarId, - string subscriberId, - string connectionId = null, - XUserClaimsInfoDto userInfo = null - ) - { - // - var result = false; - - // - // Validate ... - result = - !webinarId.IsNull() && - !webinarId.IsDefaultGuid() && - !userInfo.IsNullOrDefault() && - !subscriberId.IsNullOrEmpty(); - if (!result) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Subscription ... - result = await IsSubscribed( - webinarId: webinarId, - userInfo: userInfo, - subscriberId: subscriberId - ); - if (!result) - { - XException.NotFound.Throw(); - } - - // - // Retrieve Webinar ... - var webinar = await WebinarRepository.GetAsync(webinarId); - result = !webinar.IsNullOrDefault(); - if (!result) - { - XException.ActionFailed.Throw(); - } - - // - // Check Permissions ... - result = - userInfo.UserId == subscriberId || - userInfo.UserId == webinar.OwnerId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!result) - { - XException.NotAllowed.Throw(); - } - - // - // Retrieve Subscription Entity ... - var entity = await WebinarSubscriberRepository.FindOneAsync(ws => - ws.WebinarId == webinarId && - ws.SubscriberId == subscriberId - ); - entity = await WebinarSubscriberRepository.RemoveAsync(entity); - result = !entity.IsNullOrDefault(); - if (result) - { - // - await SendPush( - action: XWebinarEntityHubAction.Unsubscribe.GetStringValue(), - payLoad: entity.ToJSON(camelCase: true), - connectionId: connectionId - ); - } - - // - return result; - } - - /// - /// Retrieve Specified Subscriber ... - /// - /// - /// - /// - /// - public async Task GetSubscriber( - Guid webinarId, - string subscriberId, - XUserClaimsInfoDto userInfo = null - ) - { - // - // Validate ... - bool isValid = - !webinarId.IsNull() && - !webinarId.IsDefaultGuid() && - !subscriberId.IsNullOrEmpty(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Retrieve Webinar and Validate it ... - var webinar = await WebinarRepository.GetAsync(webinarId); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - isValid = - userInfo.UserId == subscriberId || - userInfo.UserId == webinar.OwnerId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - // Retrieve Entity and Validate it ... - var entity = await WebinarSubscriberRepository.FindOneAsync(e => - e.WebinarId == webinarId && - e.SubscriberId == subscriberId - ); - isValid = !entity.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - // Converts to Subscriber Dto ... - var result = await ToXWebinarSubscriberDto(entity); - return result; - } - - /// - /// Get all Specified Webinars Subscribers ... - /// - /// - /// - /// - public async Task> GetSubscribers( - Guid webinarId, - XUserClaimsInfoDto userInfo = null - ) - { - // - // Validate ... - bool isValid = - !webinarId.IsNull() && - !userInfo.IsNullOrDefault() && - !webinarId.IsDefaultGuid(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Retrieve and Validate Webinar Entity ... - var webinar = await WebinarRepository.GetAsync(webinarId); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - isValid = - (await IsSubscribed( - userInfo: userInfo, - webinarId: webinarId, - subscriberId: userInfo.UserId - )) || - userInfo.UserId == webinar.OwnerId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - var subscribers = await WebinarSubscriberRepository.FindManyAsync(e => - e.WebinarId == webinarId - ); - - // - // Prepare Result ... - var result = await subscribers - .SelectAsync(async s => await ToXWebinarSubscriberDto(s)); - - // - return result; - } - - /// - /// Query Specified Webinar's Subscribers ... - /// - /// - /// - /// - /// - public async Task> QuerySubscribers( - Guid webinarId, - XQuery query, - XUserClaimsInfoDto userInfo = null - ) - { - // - // Validate ... - bool isValid = - !query.IsNull() && - !webinarId.IsNull() && - !webinarId.IsDefaultGuid() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Normalize ... - query = query.NormalizeQuery(DataSercviceConfiguration); - - // - // Check Webinar Exists ... - var webinar = await WebinarRepository.GetAsync(webinarId); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - // Check Permissions ... - isValid = - (await IsSubscribed( - userInfo: userInfo, - webinarId: webinarId, - subscriberId: userInfo.UserId - )) || - userInfo.UserId == webinar.OwnerId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - // Retrieve all Items ... - var items = await GetSubscribers( - userInfo: userInfo, - webinarId: webinarId - ); - var totalItemsCount = items.Count(); - - // - // Try Filter Items ... - if (!query.Filter.IsNullOrEmpty()) - { - // - items = items - .ApplyFilter(query.Filter); - } - var filteredItemsCount = items.Count(); - - // - // Counting Pages ... - var totalPagesCount = query.CountPages(totalItemsCount); - var filteredPagesCount = query.CountPages(filteredItemsCount); - - // - // Apply Sorting and Paging ... - if (totalItemsCount > 0 && - filteredItemsCount > 0) - { - // - // Apply Sorting ... - items = items.ApplySorting( - query.SortBy, - query.IsAscending - ); - - // - // Apply Paging ... - items = items.ApplyPaging( - query.Page, - query.PageSize - ); - } - - // - // Prepare Result ... - var result = new XQueryResult - { - Items = items, - Page = query.Page, - PageSize = query.PageSize, - TotalPages = totalPagesCount, - TotalItems = totalItemsCount, - TotalFilteredPages = filteredPagesCount, - TotalFilteredItems = filteredItemsCount - }; - - // - return result; - } - #endregion - - // - #region File Actions ... - /// - /// Upload Files ... - /// - /// - /// - /// - /// - /// - public async Task> UploadFiles( - Guid id, - IFormFileCollection files, - XUserClaimsInfoDto userInfo = null, - string connectionId = 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 = new List(); - try - { - // - result = (await WebinarFileProvider.Upload( - files: files, - forProvidedId: id, - userInfo: userInfo, - connectionId: connectionId - )) - .ToList(); - } - catch { } - - // - return result; - } - - /// - /// Get Webinar Files ... - /// - /// - /// - /// - public async Task> GetFiles( - Guid id, - 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(); - } - - // - var result = (await WebinarFileProvider - .GetAllReferences(id)) - .ToList(); - - // - return result; - } - - /// - /// Stream Specified File of Specified Webinar ... - /// - /// - /// - /// - public async Task StreamFile( - Guid id, - Guid fileId - ) - { - // - // Validate ... - var isValid = !id.IsNull() && - !fileId.IsNull() && - !id.IsDefaultGuid() && - !fileId.IsDefaultGuid(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - var result = await WebinarFileProvider.Stream(fileId); - return result; - } - - /// - /// Download Specified File of Specified Webinar ... - /// - /// - /// - /// - public async Task DownloadFile( - Guid id, - Guid fileId - ) - { - // - // Validate ... - var isValid = !id.IsNull() && - !fileId.IsNull() && - !id.IsDefaultGuid() && - !fileId.IsDefaultGuid(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - 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, - 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 - - // - #region Tags Actions ... - /// - /// Attach Tag to Specified File ... - /// - /// - /// - /// - /// - /// - /// - public async Task AttachTag( - Guid id, - string tag, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceAttachToFiles = true - ) - { - // - // Validate ... - var isValid = - !id.IsNull() && - !id.IsDefaultGuid() && - !tag.IsNullOrEmpty() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Permissions ... - isValid = await HasPermission( - id: id, - userInfo: userInfo - ); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - try - { - // - // Attached Tag to Webinar ... - await WebinarTagProvider.AddReference( - tag: tag, - providedForId: id, - connectionId: connectionId - ); - - // - if (forceAttachToFiles) - { - // - var medias = await WebinarFileProvider.GetAllReferences(id); - isValid = !medias.IsNull() && medias.HasChild(); - if (isValid) - { - // - foreach (var media in medias) - { - // - await WebinarFileProvider.FileProvider.AttachTag( - tag: tag, - id: media.Id, - userInfo: userInfo, - connectionId: connectionId - ); - } - } - } - } - catch { } - } - - /// - /// Detach Tag fro Specified File ... - /// - /// - /// - /// - /// - /// - /// - public async Task DetachTag( - Guid id, - string tag, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceDetachFromFiles = true - ) - { - // - // Validate ... - var isValid = - !id.IsNull() && - !id.IsDefaultGuid() && - !tag.IsNullOrEmpty() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Permissions ... - isValid = await HasPermission( - id: id, - userInfo: userInfo - ); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - try - { - // - await WebinarTagProvider - .RemoveReference( - tag: tag, - 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.DetachTag( - tag: tag, - id: media.Id, - userInfo: userInfo, - connectionId: connectionId - ); - } - } - } - } - catch { } - } - - /// - /// Attach Tags for Specified File ... - /// - /// - /// - /// - /// - /// - /// - public async Task AttachTags( - Guid id, - string tags, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceAttachToFiles = true - ) - { - // - // Validate ... - var isValid = - !id.IsNull() && - !id.IsDefaultGuid() && - !tags.IsNullOrEmpty() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Permissions ... - isValid = await HasPermission( - id: id, - userInfo: userInfo - ); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - try - { - // - var tagsList = tags.ParseListString(); - foreach (var tag in tagsList) - { - // - await AttachTag( - id: id, - tag: tag, - userInfo: userInfo, - connectionId: connectionId, - forceAttachToFiles: forceAttachToFiles - ); - } - } - catch { } - } - - /// - /// Detach Tags for Specified File ... - /// - /// - /// if null, Detach All ... - /// - /// - /// - /// - public async Task DetachTags( - Guid id, - string tags, - string connectionId = null, - XUserClaimsInfoDto userInfo = null, - bool forceDetachFromFiles = true - ) - { - // - // Validate ... - var isValid = - !id.IsNull() && - !id.IsDefaultGuid() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Permissions ... - isValid = await HasPermission( - id: id, - userInfo: userInfo - ); - if (!isValid) - { - 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 tagsList) - { - // - await DetachTag( - id: id, - tag: tag, - userInfo: userInfo, - connectionId: connectionId, - forceDetachFromFiles: forceDetachFromFiles - ); - } - } - catch { } - } - - /// - /// Retrieve Specified Webinar's Tags ... - /// - /// - /// - /// - public async Task> GetTags( - Guid id, - XUserClaimsInfoDto userInfo = null - ) - { - // - // Validate Args ... - var isValid = !id.IsNull() && - !id.IsDefaultGuid() && - !userInfo.IsNullOrDefault(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Webinar Wxists ... - var webinar = await WebinarRepository.GetAsync(id); - isValid = !webinar.IsNullOrDefault(); - if (!isValid) - { - XException.NotFound.Throw(); - } - - // - // Checking Permissions ... - isValid = - (await IsSubscribed( - webinarId: id, - userInfo: userInfo, - subscriberId: userInfo.UserId - )) || - userInfo.UserId == webinar.OwnerId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - if (!isValid) - { - XException.NotAllowed.Throw(); - } - - // - // Reading Tags Dto List ... - var result = await WebinarTagProvider.GetAllReferences(id); - - // - // var result = new List(); - // isValid = !tagsDtos.IsNull() && tagsDtos.HasChild(); - // if (isValid) - // { - // // - // result = tagsDtos - // .Select(td => td.Tag) - // .ToList(); - // } - - // - return result; - } - #endregion - - // - #region Hub Actions ... - /// - /// Send Custom Push Message ... - /// - /// - /// - /// - /// - public async Task SendPush( - string action, - string payLoad, - string connectionId = null - ) - { - // - var actions = new List - { - XBaseEntityHubAction.Add.GetStringValue(), - XBaseEntityHubAction.Update.GetStringValue(), - XBaseEntityHubAction.Delete.GetStringValue(), - XBaseEntityHubAction.AddMany.GetStringValue(), - XBaseEntityHubAction.DeleteMany.GetStringValue(), - XBaseEntityHubAction.UpdateMany.GetStringValue(), - XBaseEntityHubAction.AddOrUpdate.GetStringValue(), - XWebinarEntityHubAction.Subscribe.GetStringValue(), - XWebinarEntityHubAction.Unsubscribe.GetStringValue(), - }; - - // - // Validate ... - var isValid = - !Hub.IsNull() && - !action.IsNullOrEmpty() && - actions.Contains(action); - if (!isValid) - { - return; - } - - // - var clients = Hub.Clients.All; - if (!connectionId.IsNullOrEmpty()) - { - clients = Hub.Clients.AllExcept(connectionId); - } - try - { - await clients.SendAsync(action, payLoad, connectionId); - } - catch { } - } - #endregion - - // - #region Private ... - /// - /// Check Specified User Info Has Permissions for Specified Webinar ... - /// - /// - /// - /// - private async Task HasPermission( - Guid id, - XUserClaimsInfoDto userInfo = null - ) - { - // - var result = false; - - // - // Validate ... - result = !id.IsNull() && - !id.IsDefaultGuid() && - !userInfo.IsNullOrDefault(); - if (!result) - { - XException.InvalidArgs.Throw(); - } - - // - // Check Item Exists ... - var dto = await GetWebinar(id); - result = !dto.IsNullOrDefault(); - if (!result) - { - XException.NotFound.Throw(); - } - - // - result = - dto.OwnerId == userInfo.UserId || - userInfo.Roles.Any(r => r.ToNormalString() == "admin"); - - // - return result; - } - #endregion - } -} \ No newline at end of file diff --git a/Providers/XWebinarSeederBase.cs b/Providers/XWebinarSeederBase.cs new file mode 100644 index 0000000..6625000 --- /dev/null +++ b/Providers/XWebinarSeederBase.cs @@ -0,0 +1,25 @@ +using System; +using xDataService.Configuration; +using xDataService.Providers; +using xWebinarService.Interfaces; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers +{ + public abstract class XWebinarSeederBase : XBaseDbSeeder, IXWebinarSeeder + { + public XWebinarSeederBase( + string entity, + string database, + IXWebinarRepository repository, + XDataServiceConfiguration dataServiceConfiguration + ) : base( + entity, + database, + repository, + dataServiceConfiguration + ) + { } + } +} \ No newline at end of file diff --git a/Providers/XWebinarSubscriberEntityRegisterar.cs b/Providers/XWebinarSubscriberEntityRegisterar.cs new file mode 100644 index 0000000..2f202a4 --- /dev/null +++ b/Providers/XWebinarSubscriberEntityRegisterar.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore; +using xDataService.Interfaces; +using xDataService.Providers; +using xWebinarService.Configurations.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers +{ + public class XWebinarSubscriberEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar + { + public XWebinarSubscriberEntityRegisterar() + : base(nameof(XWebinarSubscriberEntityRegisterar)) + { + // + // Add Entity ... + AddEntity(); + } + + /// + /// Configure Entities ... + /// + /// + public override void ConfigureEntities(ModelBuilder modelBuilder) + { + // + // Configure Entity Using Provided ... + modelBuilder + .ApplyConfigurationsFromAssembly(typeof(XWebinarSubscriberEntityConfiguration).Assembly); + + // + base.ConfigureEntities(modelBuilder); + } + } +} \ No newline at end of file diff --git a/Providers/XWebinarSubscriberSeederBase.cs b/Providers/XWebinarSubscriberSeederBase.cs new file mode 100644 index 0000000..f4104c4 --- /dev/null +++ b/Providers/XWebinarSubscriberSeederBase.cs @@ -0,0 +1,25 @@ +using System; +using xDataService.Configuration; +using xDataService.Providers; +using xWebinarService.Interfaces; +using xWebinarService.Interfaces.Entities; +using xWebinarService.Models.Entities; + +namespace xWebinarService.Providers +{ + public abstract class XWebinarSubscriberSeederBase : XBaseDbSeeder, IXWebinarSubscriberSeeder + { + public XWebinarSubscriberSeederBase( + string entity, + string database, + IXWebinarSubscriberRepository repository, + XDataServiceConfiguration dataServiceConfiguration + ) : base( + entity, + database, + repository, + dataServiceConfiguration + ) + { } + } +} \ No newline at end of file diff --git a/Providers/XWebinarTagProvider.cs b/Providers/XWebinarTagProvider.cs deleted file mode 100644 index c7e930e..0000000 --- a/Providers/XWebinarTagProvider.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using xTagService.Interfaces; -using xTagService.Providers; -using xWebinarService.Interfaces; -using xWebinarService.Models.Entities; - -namespace xWebinarService.Providers -{ - public class XWebinarTagProvider : XBaseTagProvider, IXWebinarTagProvider - { - public XWebinarTagProvider( - IXTagProvider tagProvider - ) : base( - providedFor: nameof(XWebinar), - tagProvider: tagProvider - ) - { } - } -} \ No newline at end of file diff --git a/Providers/XWebinarTitleResourceProvider.cs b/Providers/XWebinarTitleResourceProvider.cs deleted file mode 100644 index a233a94..0000000 --- a/Providers/XWebinarTitleResourceProvider.cs +++ /dev/null @@ -1,23 +0,0 @@ -using xCommons.Configurations; -using xStringService.Base; -using xStringService.Interfaces; -using xWebinarService.Interfaces; - -namespace xWebinarService.Providers -{ - /// - /// a Servide to Provides Requirements for XWebinar Title Resources ... - /// - public class XWebinarTitleResourceProvider : XBaseStringResourceProvider, IXWebinarTitleResourceProvider - { - public XWebinarTitleResourceProvider( - IXStringProvider provider, - XAppConfiguration appConfiguration - ) : base( - "XWEWBT", - provider, - appConfiguration - ) - { } - } -} \ No newline at end of file diff --git a/nuget.config b/nuget.config index 632defe..c6fd40c 100644 --- a/nuget.config +++ b/nuget.config @@ -1,7 +1,8 @@ + - + \ No newline at end of file diff --git a/xWebinarService.csproj b/xWebinarService.csproj index 140cc5a..7b181fc 100644 --- a/xWebinarService.csproj +++ b/xWebinarService.csproj @@ -1,12 +1,14 @@ + 1.0.0 - 8.0 + 12.0 Hadi Khazaee Asl SaherElm IT Center xDashboard.xWebinarService netstandard2.0 + it is a Part of xDashboard on SaherElm IT Center which provides all Wbinar Related Futures ...