Browse Source

code review was done.

pull/19919/head
EmreKendirli 2 years ago
parent
commit
9cc53bdbe9
  1. 2
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Volo.CmsKit.Web.Unified.csproj
  2. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs
  4. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs
  5. 16
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  6. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs
  7. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/CommentSettingViewComponent.cs
  8. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml
  9. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml
  10. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs
  11. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml
  12. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
  13. 9
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js
  14. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
  15. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs
  16. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
  17. 12
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs
  18. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  19. 14
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  20. 346
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  21. 454
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  22. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

2
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Volo.CmsKit.Web.Unified.csproj

@ -6,7 +6,7 @@
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<UserSecretsId>Volo.CmsKit-c2d31439-b723-48e2-b061-5ebd7aeb6010</UserSecretsId>
<!-- Options for DB: MongoDB, EntityFrameworkCore -->
<DefineConstants>$(DefineConstants);MongoDB</DefineConstants>
<DefineConstants>$(DefineConstants);MongoDB </DefineConstants>
</PropertyGroup>
<ItemGroup>

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

@ -1,5 +1,6 @@
using System;
using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Comments;
@ -17,7 +18,8 @@ public class CommentGetListInput : PagedAndSortedResultRequestDto
public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; }
}

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs

@ -17,6 +17,8 @@ public class CmsKitAdminPermissionDefinitionProvider : PermissionDefinitionProvi
.RequireGlobalFeatures(typeof(CommentsFeature));
contentGroup.AddChild(CmsKitAdminPermissions.Comments.Delete, L("Permission:Comments.Delete"))
.RequireGlobalFeatures(typeof(CommentsFeature));
contentGroup.AddChild(CmsKitAdminPermissions.Comments.Update, L("Permission:Comments.Update"))
.RequireGlobalFeatures(typeof(CommentsFeature));
var tagGroup = cmsGroup.AddPermission(CmsKitAdminPermissions.Tags.Default, L("Permission:TagManagement"))
.RequireGlobalFeatures(typeof(TagsFeature));

1
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs

@ -8,6 +8,7 @@ public static class CmsKitAdminPermissions
{
public const string Default = GroupName + ".Comments";
public const string Delete = Default + ".Delete";
public const string Update = Default + ".Update";
}
public static class Tags

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

@ -38,8 +38,8 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Author,
input.CreationStartDate,
input.CreationEndDate,
input.IsApproved
);
input.commentApproveStateType
);
var comments = await CommentRepository.GetListAsync(
@ -52,8 +52,8 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Sorting,
input.MaxResultCount,
input.SkipCount,
input.IsApproved
);
input.commentApproveStateType
);
var dtos = comments.Select(queryResultItem =>
{
@ -114,8 +114,8 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
}
public async Task<int> GetPendingCommentCount()
{
var count = await CommentRepository.GetCountAsync(isApproved: "null");
return (int)(count == null ? 0 : count);
var count = await CommentRepository.GetCountAsync(commentApproveStateType: CommentApproveStateType.Null);
return (int)(count);
}
@ -128,7 +128,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Author,
input.CreationStartDate,
input.CreationEndDate,
"null"
CommentApproveStateType.Null
);
@ -142,7 +142,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Sorting,
input.MaxResultCount,
input.SkipCount,
"null"
CommentApproveStateType.Null
);
var dtos = comments.Select(queryResultItem =>

13
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs

@ -51,13 +51,16 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
[HttpPost]
[Route("{id}")]
public Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto)
[Authorize(CmsKitAdminPermissions.Comments.Update)]
public Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto)
{
return CommentAdminAppService.UpdateApprovalStatusAsync(id, commentApprovalDto);
}
[HttpPost]
[Route("settings")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task SetSettings(SettingsDto settingsDto)
{
return CommentAdminAppService.SetSettings(settingsDto);
@ -65,21 +68,23 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
[HttpGet]
[Route("settings")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<SettingsDto> GetSettings()
{
return CommentAdminAppService.GetSettings();
}
[HttpGet]
[Route("waiting-count")]
public Task<int> GetPendingCommentCount()
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<int> GetPendingCommentCount()
{
return CommentAdminAppService.GetPendingCommentCount();
}
[HttpGet]
[Route("waiting")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input)
{
return CommentAdminAppService.GetWaitingCommentsWithRepliesAsync(input);

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/CommentSettingViewComponent.cs

@ -1,8 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
namespace Volo.CmsKit.Admin.Web.Components.MySettingGroup;
[Widget(
ScriptFiles = new[] { "/Components/CommentsSetting/index.js" }
)]
[ViewComponent(Name = "CmsKitCommentOptions")]
public class CommentSettingViewComponent: AbpViewComponent
{
public virtual IViewComponentResult Invoke()

2
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml

@ -10,7 +10,7 @@
<abp-script src="/client-proxies/cms-kit-admin-proxy.js" />
<abp-script src="/client-proxies/cms-kit-common-proxy.js" />
@* <abp-script src="" /> *@
<script src="/Components/CommentsSetting/index.js"></script>
@* <script src="/Components/CommentsSetting/index.js"></script> *@
</abp-script-bundle>
}
@{

13
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml

@ -5,6 +5,7 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments
@using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Comments
@using Volo.CmsKit.Localization
@inject IPageLayout PageLayout
@ -94,13 +95,13 @@
<abp-input asp-for="@Model.Author" label="@L["Username"].Value" type="text"/>
</abp-column>
<abp-column size-lg="_2" size-md="_12">
<div class="mb-3">
<div class="mb-3" id="isApprovedColumn">
<label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label>
<select id="isApprovedSelect" asp-for="@Model.IsApproved" class="form-control">
<option value="">@L["CommentFilter:All"].Value</option>
<option value="true">@L["CommentFilter:Approved"].Value</option>
<option value="false">@L["CommentFilter:Disapproved"].Value</option>
<option value="null">@L["CommentFilter:Waiting"].Value</option>
<select id="isApprovedSelect" asp-for="@Model.commentApproveStateType" class="form-control">
<option value="@CommentApproveStateType.All">@L["CommentFilter:All"].Value</option>
<option value="@CommentApproveStateType.True">@L["CommentFilter:Approved"].Value</option>
<option value="@CommentApproveStateType.False">@L["CommentFilter:Disapproved"].Value</option>
<option value="@CommentApproveStateType.Null">@L["CommentFilter:Waiting"].Value</option>
</select>
</div>
</abp-column>

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.CmsKit.Admin.Comments;
using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments;
@ -15,7 +16,9 @@ public class DetailsModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; }
//public string IsApproved { get; set; }
public CommentWithAuthorDto CommentWithAuthorDto { get; protected set; }

13
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml

@ -4,6 +4,7 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments
@using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Comments
@using Volo.CmsKit.Localization
@inject IPageLayout PageLayout
@ -59,13 +60,13 @@
</abp-column>
<abp-column size-lg="_2" size-md="_6">
<div class="mb-3">
<div class="mb-3" id="isApprovedColumn">
<label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label>
<select id="isApprovedSelect" asp-for="@Model.IsApproved" class="form-control">
<option value="">@L["CommentFilter:All"].Value</option>
<option value="true">@L["CommentFilter:Approved"].Value</option>
<option value="false">@L["CommentFilter:Disapproved"].Value</option>
<option value="null">@L["CommentFilter:Waiting"].Value</option>
<select id="isApprovedSelect" asp-for="@Model.commentApproveStateType" class="form-control">
<option value="@CommentApproveStateType.All">@L["CommentFilter:All"].Value</option>
<option value="@CommentApproveStateType.True">@L["CommentFilter:Approved"].Value</option>
<option value="@CommentApproveStateType.False">@L["CommentFilter:Disapproved"].Value</option>
<option value="@CommentApproveStateType.Null">@L["CommentFilter:Waiting"].Value</option>
</select>
</div>
</abp-column>

3
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs

@ -1,4 +1,5 @@
using System;
using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments;
@ -11,6 +12,6 @@ public class IndexModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; } = null;
public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; }
}

9
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js

@ -200,7 +200,14 @@ $(function (){
_dataTable.ajax.reloadEx();
});
commentsService.getSettings().then(function (data) {
if (data.requireApprovement) {
$('#CommentsTable').DataTable().column(4).visible(true);
} else {
$('#CommentsTable').DataTable().column(4).visible(false);
$('#isApprovedColumn').hide();
}
})
filterForm.submit(function (e){
e.preventDefault();
_dataTable.ajax.reloadEx();

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js

@ -236,11 +236,11 @@ $(function (){
e.preventDefault();
_dataTable.ajax.reloadEx();
});
// Get and display pending comment count
commentsService.getPendingCommentCount().then(function (count) {
console.log(count)
if (count > 0) {
var alertMessage = l("CommentAlertMessage") + count + "";
var alertMessage = l("CommentAlertMessage", count);
var alertElement = '<abp-alert alert-type="Warning">' + alertMessage + '</abp-alert>';
$('#commentsAlert').html(alertElement);
$('#commentsAlert').show()
@ -256,6 +256,7 @@ $(function (){
$('#CommentsTable').DataTable().column(6).visible(true);
} else {
$('#CommentsTable').DataTable().column(6).visible(false);
$('#isApprovedColumn').hide();
}
})
});

3
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.SettingManagement.Web.Pages.SettingManagement;
using Volo.CmsKit.Admin.Web.Components.MySettingGroup;
using Volo.CmsKit.Localization;
@ -9,7 +10,6 @@ namespace Volo.CmsKit.Admin.Web.Settings;
public class CommentSettingPageContributor : ISettingPageContributor
{
public Task ConfigureAsync(SettingPageCreationContext context)
{
var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<CmsKitResource>>();
@ -22,6 +22,7 @@ public class CommentSettingPageContributor : ISettingPageContributor
)
);
return Task.CompletedTask;
}

4
modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js

@ -176,7 +176,7 @@
volo.cmsKit.admin.comments.commentAdmin.getList = function(input, ajaxParams) {
return abp.ajax($.extend(true, {
url: abp.appPath + 'api/cms-kit-admin/comments' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'isApproved', value: input.isApproved }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
url: abp.appPath + 'api/cms-kit-admin/comments' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'commentApproveStateType', value: input.commentApproveStateType }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
type: 'GET'
}, ajaxParams));
};
@ -230,7 +230,7 @@
volo.cmsKit.admin.comments.commentAdmin.getWaitingCommentsWithReplies = function(input, ajaxParams) {
return abp.ajax($.extend(true, {
url: abp.appPath + 'api/cms-kit-admin/comments/waiting' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'isApproved', value: input.isApproved }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
url: abp.appPath + 'api/cms-kit-admin/comments/waiting' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'commentApproveStateType', value: input.commentApproveStateType }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
type: 'GET'
}, ajaxParams));
};

12
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.CmsKit.Comments;
public enum CommentApproveStateType
{
All,
True,
False,
Null
}

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -246,7 +246,7 @@
"Approve":"Approve",
"Disapproved":"Disapproved",
"CommentAlertMessage":"You have waiting comments: ",
"CommentAlertMessage":"There are {0} comments waiting for approval",
"Menu:CmsKitCommentOptions":"CmsKit Comment Options"
}

14
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs

@ -21,26 +21,26 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string isApproved = null,
CancellationToken cancellationToken = default
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string text = null,
string text = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string isApproved = null,
CancellationToken cancellationToken = default
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
);
Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType,
[NotNull] string entityId,
bool? isApproved,
CancellationToken cancellationToken = default
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
);
Task DeleteWithRepliesAsync(

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

@ -15,179 +15,189 @@ using Volo.CmsKit.Users;
namespace Volo.CmsKit.Comments;
public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Comment, Guid>,
ICommentRepository
ICommentRepository
{
public EfCoreCommentRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id,
CancellationToken cancellationToken = default)
{
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where id == comment.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (commentWithAuthor == null)
{
throw new EntityNotFoundException(typeof(Comment), id);
}
return commentWithAuthor;
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool? isApproved = null,
CancellationToken cancellationToken = default
)
{
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
filter,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
isApproved,
token);
if (!sorting.IsNullOrEmpty())
{
sorting = "comment." + sorting;
}
query = query.OrderBy(sorting.IsNullOrEmpty() ? "comment.creationTime desc" : sorting)
.PageBy(skipCount, maxResultCount);
return await query.ToListAsync(token);
}
public virtual async Task<long> GetCountAsync(
string text = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
bool? isApproved = null,
CancellationToken cancellationToken = default
)
{
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
text,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
isApproved,
token);
return await query.LongCountAsync(token);
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,
bool ? isApproved = null,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId
public EfCoreCommentRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id,
CancellationToken cancellationToken = default)
{
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where id == comment.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (commentWithAuthor == null)
{
throw new EntityNotFoundException(typeof(Comment), id);
}
return commentWithAuthor;
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
)
{
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
filter,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
commentApproveStateType,
token);
if (!sorting.IsNullOrEmpty())
{
sorting = "comment." + sorting;
}
query = query.OrderBy(sorting.IsNullOrEmpty() ? "comment.creationTime desc" : sorting)
.PageBy(skipCount, maxResultCount);
return await query.ToListAsync(token);
}
public virtual async Task<long> GetCountAsync(
string text = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
)
{
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
text,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
commentApproveStateType,
token);
return await query.LongCountAsync(token);
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
if (isApproved.HasValue)
if (CommentApproveStateType.True == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == true);
}
else if (CommentApproveStateType.False == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == isApproved.Value);
query = query.Where(c => c.Comment.IsApproved == false);
}
else if (CommentApproveStateType.Null == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == null);
}
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task DeleteWithRepliesAsync(
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await (await GetDbSetAsync())
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var reply in replies)
{
await DeleteAsync(
reply,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<CommentWithAuthorQueryResultItem>> GetListQueryAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
bool? isApproved = null,
CancellationToken cancellationToken = default
)
{
var commentDbSet = await GetDbSetAsync();
var cmsUserSet = (await GetDbContextAsync()).Set<CmsUser>();
var query = from comment in commentDbSet
join user in cmsUserSet
on comment.CreatorId equals user.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType))
.WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId)
.WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername))
.WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate)
.WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved);
}
}
public virtual async Task DeleteWithRepliesAsync(
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await (await GetDbSetAsync())
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var reply in replies)
{
await DeleteAsync(
reply,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<CommentWithAuthorQueryResultItem>> GetListQueryAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
)
{
var commentDbSet = await GetDbSetAsync();
var cmsUserSet = (await GetDbContextAsync()).Set<CmsUser>();
var query = from comment in commentDbSet
join user in cmsUserSet
on comment.CreatorId equals user.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType))
.WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId)
.WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername))
.WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate)
.WhereIf(CommentApproveStateType.True == commentApproveStateType, c => c.Comment.IsApproved == true)
.WhereIf(CommentApproveStateType.False == commentApproveStateType, c => c.Comment.IsApproved == false)
.WhereIf(CommentApproveStateType.Null == commentApproveStateType, c => c.Comment.IsApproved == null);
//.WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved);
}
}

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

@ -16,231 +16,231 @@ namespace Volo.CmsKit.MongoDB.Comments;
public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, Comment, Guid>, ICommentRepository
{
public MongoCommentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
{
var comment = await GetAsync(id);
var author = await (await GetDbContextAsync())
.CmsUsers
.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken));
return new CommentWithAuthorQueryResultItem()
{
Comment = comment,
Author = author
};
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string isApproved = null,
CancellationToken cancellationToken = default
)
{
//bool? isApprovedValue = ParseIsApproved(isApproved);
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
filter,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
isApproved,
token);
var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
.As<IMongoQueryable<Comment>>()
.PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount)
.ToListAsync(token);
var commentIds = comments.Select(x => x.Id).ToList();
var authorsQuery = from comment in (await GetMongoQueryableAsync(token))
join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
where commentIds.Contains(comment.Id)
orderby comment.CreationTime
select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token);
return comments
.Select(
comment =>
new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList();
}
public virtual async Task<long> GetCountAsync(
string text = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string isApproved = null,
CancellationToken cancellationToken = default
)
{
//bool? isApprovedValue = ParseIsApproved(isApproved);
var query = await GetListQueryAsync(
text,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
isApproved,
cancellationToken);
return await query.As<IMongoQueryable<Comment>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,
bool? isApproved,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken))
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime
select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType);
commentsQuery = isApproved.Value ?
commentsQuery.Where(c => c.IsApproved == true) :
commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null);
var comments = await commentsQuery
.OrderBy(c => c.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken));
return comments
.Select(
comment =>
new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList();
}
public virtual async Task DeleteWithRepliesAsync(
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
await base.DeleteAsync(
comment,
cancellationToken: GetCancellationToken(cancellationToken)
);
foreach (var reply in replies)
{
await base.DeleteAsync(
reply,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
}
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string isApproved = null,
CancellationToken cancellationToken = default
)
{
var queryable = await GetMongoQueryableAsync(cancellationToken);
if (!string.IsNullOrEmpty(authorUsername))
{
var author = await (await GetMongoQueryableAsync<CmsUser>(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
var authorId = author?.Id ?? Guid.Empty;
queryable = queryable.Where(x => x.CreatorId == authorId);
}
queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
if (!string.IsNullOrWhiteSpace(isApproved))
{
bool? isApprovedValue = ParseIsApproved(isApproved);
if (isApprovedValue.HasValue)
{
queryable = queryable.Where(c => c.IsApproved == isApprovedValue);
}
else if (isApprovedValue == null)
{
queryable = queryable.Where(c => c.IsApproved == null);
}
}
return queryable;
}
public static bool? ParseIsApproved(string isApproved)
{
if (string.IsNullOrWhiteSpace(isApproved))
{
return null;
}
return isApproved.ToLower() switch
{
"true" => true,
"false" => false,
"null" => (bool?)null,
_ => null
};
}
public MongoCommentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
{
var comment = await GetAsync(id);
var author = await (await GetDbContextAsync())
.CmsUsers
.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken));
return new CommentWithAuthorQueryResultItem()
{
Comment = comment,
Author = author
};
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
)
{
//bool? isApprovedValue = ParseIsApproved(isApproved);
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(
filter,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
commentApproveStateType,
token);
var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
.As<IMongoQueryable<Comment>>()
.PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount)
.ToListAsync(token);
var commentIds = comments.Select(x => x.Id).ToList();
var authorsQuery = from comment in (await GetMongoQueryableAsync(token))
join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
where commentIds.Contains(comment.Id)
orderby comment.CreationTime
select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token);
return comments
.Select(
comment =>
new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList();
}
public virtual async Task<long> GetCountAsync(
string text = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
)
{
//bool? isApprovedValue = ParseIsApproved(isApproved);
var query = await GetListQueryAsync(
text,
entityType,
repliedCommentId,
authorUsername,
creationStartDate,
creationEndDate,
commentApproveStateType,
cancellationToken);
return await query.As<IMongoQueryable<Comment>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken))
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime
select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType);
commentsQuery = (IMongoQueryable<Comment>)FilterCommentsByApprovalState(commentsQuery, commentApproveStateType);
var comments = await commentsQuery
.OrderBy(c => c.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken));
return comments
.Select(
comment =>
new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList();
}
public virtual async Task DeleteWithRepliesAsync(
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
await base.DeleteAsync(
comment,
cancellationToken: GetCancellationToken(cancellationToken)
);
foreach (var reply in replies)
{
await base.DeleteAsync(
reply,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
}
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
string filter = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
)
{
var queryable = await GetMongoQueryableAsync(cancellationToken);
if (!string.IsNullOrEmpty(authorUsername))
{
var author = await (await GetMongoQueryableAsync<CmsUser>(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
var authorId = author?.Id ?? Guid.Empty;
queryable = queryable.Where(x => x.CreatorId == authorId);
}
queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
//.WhereIf(CommentApproveStateType.True == commentApproveStateType, c => c.IsApproved == true)
//.WhereIf(CommentApproveStateType.False == commentApproveStateType, c => c.IsApproved == false)
//.WhereIf(CommentApproveStateType.Null == commentApproveStateType, c => c.IsApproved == null);
if (CommentApproveStateType.True == commentApproveStateType)
{
queryable = queryable.Where(c => c.IsApproved == true);
}
else if (CommentApproveStateType.False == commentApproveStateType)
{
queryable = queryable.Where(c => c.IsApproved == false);
}
else if (CommentApproveStateType.Null == commentApproveStateType)
{
queryable = queryable.Where(c => c.IsApproved == null);
}
return queryable;
}
public IQueryable<Comment> FilterCommentsByApprovalState(IQueryable<Comment> commentsQuery, CommentApproveStateType approveState)
{
switch (approveState)
{
case CommentApproveStateType.True:
commentsQuery = commentsQuery.Where(c => c.IsApproved == true);
break;
case CommentApproveStateType.False:
commentsQuery = commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null);
break;
}
return commentsQuery;
}
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

@ -58,8 +58,10 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli
public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId)
{
string state = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement);
var commentsWithAuthor = bool.Parse(state) ?
await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.True) :
await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.False);
var commentsWithAuthor = await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, bool.Parse(state));
return new ListResultDto<CommentWithDetailsDto>(
ConvertCommentsToNestedStructure(commentsWithAuthor)

Loading…
Cancel
Save