Add support of Tag and File Provider to Webinar Provider ...
required to Implement Uploading ...
This commit is contained in:
@@ -2,12 +2,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
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;
|
||||
@@ -18,6 +20,7 @@ using xWebinarService.Interfaces;
|
||||
using xWebinarService.Interfaces.Entities;
|
||||
using xWebinarService.Models.Dtos;
|
||||
using xWebinarService.Models.Entities;
|
||||
using XFileDto = xFileService.Models.Dtos.XFileDto;
|
||||
|
||||
namespace xWebinarService.Providers
|
||||
{
|
||||
@@ -31,6 +34,8 @@ namespace xWebinarService.Providers
|
||||
public IHubContext<XWebinarEntityHub> 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; }
|
||||
@@ -42,6 +47,8 @@ namespace xWebinarService.Providers
|
||||
public XWebinarProvider(
|
||||
IXIdentityProvider identityProvider,
|
||||
IXWebinarRepository webinarRepository,
|
||||
IXWebinarTagProvider webinarTagProvider,
|
||||
IXWebinarFileProvider webinarFileProvider,
|
||||
XDataServiceConfiguration dataSercviceConfiguration,
|
||||
IXWebinarTitleResourceProvider titleResourceProvider,
|
||||
IXWebinarSubscriberRepository webinarSubscriberRepository,
|
||||
@@ -50,13 +57,15 @@ namespace xWebinarService.Providers
|
||||
)
|
||||
{
|
||||
//
|
||||
Hub = hub;
|
||||
IdentityProvider = identityProvider;
|
||||
WebinarRepository = webinarRepository;
|
||||
DataSercviceConfiguration = dataSercviceConfiguration;
|
||||
WebinarTagProvider = webinarTagProvider;
|
||||
WebinarFileProvider = webinarFileProvider;
|
||||
TitleResourceProvider = titleResourceProvider;
|
||||
DataSercviceConfiguration = dataSercviceConfiguration;
|
||||
WebinarSubscriberRepository = webinarSubscriberRepository;
|
||||
DescriptionResourceProvider = descriptionResourceProvider;
|
||||
Hub = hub;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -1143,6 +1152,347 @@ namespace xWebinarService.Providers
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region File Actions ...
|
||||
/// <summary>
|
||||
/// Upload Files ...
|
||||
/// </summary>
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XFileDto>> Upload(
|
||||
Guid id,
|
||||
IFormFileCollection files,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !id.IsNull() &&
|
||||
!id.IsDefaultGuid() &&
|
||||
!userInfo.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Permission ...
|
||||
isValid = await HasPermission(id, userInfo);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = new List<XFileDto>();
|
||||
try
|
||||
{
|
||||
//
|
||||
result = (await WebinarFileProvider.Upload(
|
||||
files: files,
|
||||
forProvidedId: id,
|
||||
userInfo: userInfo
|
||||
))
|
||||
.ToList();
|
||||
}
|
||||
catch { }
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Webinar Files ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XFileDto>> GetFiles(Guid id)
|
||||
{
|
||||
//
|
||||
var result = new List<XFileDto>();
|
||||
|
||||
//
|
||||
var dto = await GetWebinar(id);
|
||||
if (!dto.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
result = (await WebinarFileProvider
|
||||
.GetAllFor(id))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Tags Actions ...
|
||||
/// <summary>
|
||||
/// Attach Tag to Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="forceAttachToFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagAttach(
|
||||
string tag,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
bool forceAttachToFiles = true
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !tag.IsNullOrEmpty() &&
|
||||
!id.IsNull() &&
|
||||
!id.IsDefaultGuid() &&
|
||||
!userInfo.IsNullOrDefault();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Check Permissions ...
|
||||
isValid = await HasPermission(
|
||||
id: id,
|
||||
userInfo: userInfo
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Attached Tag to Webinar ...
|
||||
await WebinarTagProvider.Attach(tag, id);
|
||||
|
||||
//
|
||||
if (forceAttachToFiles)
|
||||
{
|
||||
//
|
||||
var medias = await WebinarFileProvider.GetAllFor(id);
|
||||
isValid = !medias.IsNull() && medias.HasChild();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
foreach (var media in medias)
|
||||
{
|
||||
await WebinarFileProvider.Provider.TagAttach(tag, media.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detach Tag fro Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="forceAttachToFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagDetach(
|
||||
string tag,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
bool forceDetachFromFiles = true
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !tag.IsNullOrEmpty() &&
|
||||
!id.IsNull() &&
|
||||
!id.IsDefaultGuid();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Check Permissions ...
|
||||
isValid = await HasPermission(
|
||||
id: id,
|
||||
userInfo: userInfo
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
await WebinarTagProvider.Detach(tag, id);
|
||||
|
||||
//
|
||||
if (forceDetachFromFiles)
|
||||
{
|
||||
//
|
||||
var medias = await WebinarFileProvider.GetAllFor(id);
|
||||
isValid = !medias.IsNull() && medias.HasChild();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
foreach (var media in medias)
|
||||
{
|
||||
await WebinarFileProvider.Provider.TagDetach(tag, media.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attach Tags for Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="forceAttachToFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsAttach(
|
||||
IEnumerable<string> tags,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
bool forceAttachToFiles = true
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !tags.IsNull() &&
|
||||
tags.HasChild() &&
|
||||
!id.IsNull() &&
|
||||
!id.IsDefaultGuid();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Check Permissions ...
|
||||
isValid = await HasPermission(
|
||||
id: id,
|
||||
userInfo: userInfo
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
//
|
||||
await TagAttach(
|
||||
tag,
|
||||
id,
|
||||
userInfo,
|
||||
forceAttachToFiles
|
||||
);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detach Tags for Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="forceDetachFromFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsDetach(
|
||||
IEnumerable<string> tags,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
bool forceDetachFromFiles = true
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !tags.IsNull() &&
|
||||
tags.HasChild() &&
|
||||
!id.IsNull() &&
|
||||
!id.IsDefaultGuid();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Check Permissions ...
|
||||
isValid = await HasPermission(
|
||||
id: id,
|
||||
userInfo: userInfo
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
//
|
||||
await TagDetach(
|
||||
tag,
|
||||
id,
|
||||
userInfo,
|
||||
forceDetachFromFiles
|
||||
);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detach all Attached Tags for Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsDetach(
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !id.IsNull() && !id.IsDefaultGuid();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
// Check Permissions ...
|
||||
isValid = await HasPermission(
|
||||
id: id,
|
||||
userInfo: userInfo
|
||||
);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var tags = await WebinarTagProvider.RemoveTagsFor(id);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Hub Actions ...
|
||||
/// <summary>
|
||||
@@ -1196,5 +1546,50 @@ namespace xWebinarService.Providers
|
||||
catch { }
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// Check Specified User Info Has Permissions for Specified Webinar ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user