Browse Source

refactoring

pull/7757/head
Ahmet 6 years ago
parent
commit
afd9cd9d39
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs
  2. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  3. 49
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  4. 8
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs

@ -13,7 +13,7 @@ namespace Volo.CmsKit.Admin.Comments
public Guid? RepliedCommentId { get; set; }
public string AuthorUserName { get; set; }
public string Author { get; set; }
public DateTime? CreationStartDate { get; set; }

5
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
@ -30,7 +29,7 @@ namespace Volo.CmsKit.Admin.Comments
input.EntityType,
input.EntityId,
input.RepliedCommentId,
input.AuthorUserName,
input.Author,
input.CreationStartDate,
input.CreationEndDate);
@ -39,7 +38,7 @@ namespace Volo.CmsKit.Admin.Comments
input.EntityType,
input.EntityId,
input.RepliedCommentId,
input.AuthorUserName,
input.Author,
input.CreationStartDate,
input.CreationEndDate,
input.Sorting,

49
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -66,19 +66,15 @@ namespace Volo.CmsKit.Comments
creationStartDate,
creationEndDate);
query = query.OrderBy(sorting ?? "creationTime desc")
.PageBy(skipCount, maxResultCount);
if (sorting != null)
{
sorting = "comment." + sorting;
}
var query2 = from comment in query
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
orderby comment.CreationTime
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
query = query.OrderBy(sorting ?? "comment.creationTime desc")
.PageBy(skipCount, maxResultCount);
return await query2.ToListAsync(GetCancellationToken(cancellationToken));
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<long> GetCountAsync(
@ -144,7 +140,7 @@ namespace Volo.CmsKit.Comments
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
protected virtual async Task<IQueryable<CommentWithAuthorQueryResultItem>> GetListQueryAsync(
string filter = null,
string entityType = null,
string entityId = null,
@ -154,25 +150,30 @@ namespace Volo.CmsKit.Comments
DateTime? creationEndDate = null
)
{
var dbSet = await GetDbSetAsync();
var queryable = dbSet.AsQueryable();
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>()
on comment.CreatorId equals user.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
if (string.IsNullOrEmpty(authorUsername))
if (!string.IsNullOrWhiteSpace(authorUsername))
{
var author = await (await GetDbContextAsync()).User.FirstOrDefaultAsync(x => x.UserName == authorUsername);
var author = await (await GetDbContextAsync()).Set<CmsUser>().FirstOrDefaultAsync(x => x.UserName == authorUsername);
var authorId = author?.Id ?? Guid.Empty;
queryable.Where(x => x.CreatorId == authorId);
query = query.Where(x => x.Comment.CreatorId == authorId);
}
return (dbSet)
.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType.Contains(entityType))
.WhereIf(!entityId.IsNullOrWhiteSpace(), c => c.EntityId.Contains(entityId))
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType))
.WhereIf(!entityId.IsNullOrWhiteSpace(), c => c.Comment.EntityId.Contains(entityId))
.WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId)
.WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate);
}
}
}

8
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -182,15 +182,15 @@ namespace Volo.CmsKit.MongoDB.Comments
{
var queryable = await GetMongoQueryableAsync(cancellationToken);
if (string.IsNullOrEmpty(authorUsername))
if (!string.IsNullOrEmpty(authorUsername))
{
var authorQuerable = (await GetDbContextAsync(cancellationToken)).Collection<CmsUser>().AsQueryable();
var authorQueryable = (await GetDbContextAsync(cancellationToken)).Collection<CmsUser>().AsQueryable();
var author = await authorQuerable.FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
var author = await authorQueryable.FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
var authorId = author?.Id ?? Guid.Empty;
queryable.Where(x => x.CreatorId == authorId);
queryable = queryable.Where(x => x.CreatorId == authorId);
}
return queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))

Loading…
Cancel
Save