last works ...
This commit is contained in:
+230
-21
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
@@ -334,6 +335,7 @@ namespace xWebinarService.Providers
|
||||
tags: tags,
|
||||
id: entity.Id,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId,
|
||||
true //
|
||||
);
|
||||
}
|
||||
@@ -366,6 +368,10 @@ namespace xWebinarService.Providers
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
// Since Medias and Tags Manages Separatly, here
|
||||
// we dont need to ensure that ...
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool isValid =
|
||||
@@ -584,7 +590,6 @@ namespace xWebinarService.Providers
|
||||
// Since in Resourceable Entities we have to Search on Locales
|
||||
// we Must Implement Senario Custom ...
|
||||
var totalEntities = await WebinarRepository.GetAllAsync();
|
||||
Console.WriteLine($"Query Reading All ...");
|
||||
|
||||
//
|
||||
var list = new List<XWebinarDto>();
|
||||
@@ -596,7 +601,6 @@ namespace xWebinarService.Providers
|
||||
}
|
||||
var items = list.AsEnumerable();
|
||||
var totalItemsCount = items.Count();
|
||||
Console.WriteLine($"Query Reading Item's Tasks ...");
|
||||
|
||||
//
|
||||
// Apply Filter ...
|
||||
@@ -605,9 +609,6 @@ namespace xWebinarService.Providers
|
||||
//
|
||||
items = items
|
||||
.ApplyFilter(query.Filter);
|
||||
|
||||
//
|
||||
Console.WriteLine($"Query Apply Filter ...");
|
||||
}
|
||||
int filteredItemsCount = items.Count();
|
||||
|
||||
@@ -629,8 +630,6 @@ namespace xWebinarService.Providers
|
||||
query.SortBy,
|
||||
query.IsAscending
|
||||
);
|
||||
//
|
||||
Console.WriteLine($"Query Apply Sorting ...");
|
||||
|
||||
//
|
||||
// Apply Paging ...
|
||||
@@ -640,8 +639,6 @@ namespace xWebinarService.Providers
|
||||
query.Page,
|
||||
query.PageSize
|
||||
);
|
||||
//
|
||||
Console.WriteLine($"Query Apply Paging ...");
|
||||
}
|
||||
|
||||
//
|
||||
@@ -661,6 +658,170 @@ namespace xWebinarService.Providers
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conditional Query Webinars ...
|
||||
/// </summary>
|
||||
/// <param name="whereClause"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XWebinarDto>> ConditionalQueryWebinars(
|
||||
Expression<Func<XWebinarDto, bool>> 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<XWebinarDto>();
|
||||
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<XWebinarDto>
|
||||
{
|
||||
Page = query.Page,
|
||||
Items = items.ToList(),
|
||||
PageSize = query.PageSize,
|
||||
TotalPages = totalPagesCount,
|
||||
TotalItems = totalItemsCount,
|
||||
TotalFilteredPages = filteredPagesCount,
|
||||
TotalFilteredItems = filteredItemsCount
|
||||
};
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Owned Webinars ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XWebinarDto>> QueryOwnedWebinars(
|
||||
XQuery query,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !query.IsNullOrDefault() &&
|
||||
!userInfo.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
Expression<Func<XWebinarDto, bool>> whereClause = d => d.OwnerId == userInfo.UserId;
|
||||
var result = await ConditionalQueryWebinars(
|
||||
query: query,
|
||||
whereClause: whereClause
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Joinable Webinars ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XWebinarDto>> 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<Func<XWebinarDto, bool>> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Webinar Ids ...
|
||||
/// </summary>
|
||||
@@ -1246,11 +1407,13 @@ namespace xWebinarService.Providers
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XFileDto>> Upload(
|
||||
Guid id,
|
||||
IFormFileCollection files,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1279,7 +1442,8 @@ namespace xWebinarService.Providers
|
||||
result = (await WebinarFileProvider.Upload(
|
||||
files: files,
|
||||
forProvidedId: id,
|
||||
userInfo: userInfo
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId
|
||||
))
|
||||
.ToList();
|
||||
}
|
||||
@@ -1295,11 +1459,13 @@ namespace xWebinarService.Providers
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<Guid>> RemoveFiles(
|
||||
Guid id,
|
||||
string ids = null,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1322,9 +1488,10 @@ namespace xWebinarService.Providers
|
||||
|
||||
//
|
||||
var result = await WebinarFileProvider.Remove(
|
||||
id,
|
||||
ids,
|
||||
userInfo
|
||||
forProvidedId: id,
|
||||
ids: ids,
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@@ -1362,12 +1529,14 @@ namespace xWebinarService.Providers
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="forceAttachToFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagAttach(
|
||||
string tag,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
bool forceAttachToFiles = true
|
||||
)
|
||||
{
|
||||
@@ -1395,7 +1564,7 @@ namespace xWebinarService.Providers
|
||||
{
|
||||
//
|
||||
// Attached Tag to Webinar ...
|
||||
await WebinarTagProvider.Attach(tag, id);
|
||||
await WebinarTagProvider.Attach(tag, id, connectionId);
|
||||
|
||||
//
|
||||
if (forceAttachToFiles)
|
||||
@@ -1408,7 +1577,13 @@ namespace xWebinarService.Providers
|
||||
//
|
||||
foreach (var media in medias)
|
||||
{
|
||||
await WebinarFileProvider.Provider.TagAttach(tag, media.Id);
|
||||
//
|
||||
await WebinarFileProvider.Provider.TagAttach(
|
||||
tag,
|
||||
media.Id,
|
||||
userInfo,
|
||||
connectionId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1423,12 +1598,14 @@ namespace xWebinarService.Providers
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="forceAttachToFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagDetach(
|
||||
string tag,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
bool forceDetachFromFiles = true
|
||||
)
|
||||
{
|
||||
@@ -1454,7 +1631,7 @@ namespace xWebinarService.Providers
|
||||
try
|
||||
{
|
||||
//
|
||||
await WebinarTagProvider.Detach(tag, id);
|
||||
await WebinarTagProvider.Detach(tag, id, connectionId);
|
||||
|
||||
//
|
||||
if (forceDetachFromFiles)
|
||||
@@ -1467,7 +1644,13 @@ namespace xWebinarService.Providers
|
||||
//
|
||||
foreach (var media in medias)
|
||||
{
|
||||
await WebinarFileProvider.Provider.TagDetach(tag, media.Id);
|
||||
//
|
||||
await WebinarFileProvider.Provider.TagDetach(
|
||||
tag,
|
||||
media.Id,
|
||||
userInfo,
|
||||
connectionId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1482,12 +1665,14 @@ namespace xWebinarService.Providers
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="forceAttachToFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsAttach(
|
||||
IEnumerable<string> tags,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
bool forceAttachToFiles = true
|
||||
)
|
||||
{
|
||||
@@ -1521,6 +1706,7 @@ namespace xWebinarService.Providers
|
||||
tag,
|
||||
id,
|
||||
userInfo,
|
||||
connectionId,
|
||||
forceAttachToFiles
|
||||
);
|
||||
}
|
||||
@@ -1535,12 +1721,14 @@ namespace xWebinarService.Providers
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="forceDetachFromFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsDetach(
|
||||
IEnumerable<string> tags,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
bool forceDetachFromFiles = true
|
||||
)
|
||||
{
|
||||
@@ -1574,6 +1762,7 @@ namespace xWebinarService.Providers
|
||||
tag,
|
||||
id,
|
||||
userInfo,
|
||||
connectionId,
|
||||
forceDetachFromFiles
|
||||
);
|
||||
}
|
||||
@@ -1586,10 +1775,14 @@ namespace xWebinarService.Providers
|
||||
/// Detach all Attached Tags for Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="forceDetachFromFiles"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsDetach(
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null,
|
||||
bool forceDetachFromFiles = true
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1612,7 +1805,23 @@ namespace xWebinarService.Providers
|
||||
try
|
||||
{
|
||||
//
|
||||
var tags = await WebinarTagProvider.RemoveTagsFor(id);
|
||||
var tags = await WebinarTagProvider.RemoveTagsFor(id, connectionId);
|
||||
|
||||
//
|
||||
if (forceDetachFromFiles)
|
||||
{
|
||||
//
|
||||
var medias = await WebinarFileProvider.GetAllFor(id);
|
||||
if (!medias.IsNull() && medias.HasChild())
|
||||
{
|
||||
//
|
||||
foreach (var media in medias)
|
||||
{
|
||||
//
|
||||
await WebinarFileProvider.Provider.TagsDetach(media.Id, userInfo, connectionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user