mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.6 KiB
109 lines
3.6 KiB
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.Features;
|
|
using Volo.Abp.GlobalFeatures;
|
|
using Volo.CmsKit.Comments;
|
|
using Volo.CmsKit.Features;
|
|
using Volo.CmsKit.GlobalFeatures;
|
|
using Volo.CmsKit.Permissions;
|
|
using Volo.CmsKit.Users;
|
|
|
|
namespace Volo.CmsKit.Admin.Comments;
|
|
|
|
[RequiresFeature(CmsKitFeatures.CommentEnable)]
|
|
[RequiresGlobalFeature(typeof(CommentsFeature))]
|
|
[Authorize(CmsKitAdminPermissions.Comments.Default)]
|
|
public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAppService
|
|
{
|
|
protected ICommentRepository CommentRepository { get; }
|
|
|
|
private readonly ISettingManager SettingManager;
|
|
public CommentAdminAppService(ICommentRepository commentRepository, ISettingManager settingManager)
|
|
{
|
|
CommentRepository = commentRepository;
|
|
SettingManager = settingManager;
|
|
}
|
|
|
|
public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input)
|
|
{
|
|
var totalCount = await CommentRepository.GetCountAsync(
|
|
input.Text,
|
|
input.EntityType,
|
|
input.RepliedCommentId,
|
|
input.Author,
|
|
input.CreationStartDate,
|
|
input.CreationEndDate);
|
|
|
|
var comments = await CommentRepository.GetListAsync(
|
|
input.Text,
|
|
input.EntityType,
|
|
input.RepliedCommentId,
|
|
input.Author,
|
|
input.CreationStartDate,
|
|
input.CreationEndDate,
|
|
input.Sorting,
|
|
input.MaxResultCount,
|
|
input.SkipCount
|
|
);
|
|
|
|
var dtos = comments.Select(queryResultItem =>
|
|
{
|
|
var dto = ObjectMapper.Map<Comment, CommentWithAuthorDto>(queryResultItem.Comment);
|
|
dto.Author = ObjectMapper.Map<CmsUser, CmsUserDto>(queryResultItem.Author);
|
|
|
|
return dto;
|
|
}).ToList();
|
|
|
|
return new PagedResultDto<CommentWithAuthorDto>(totalCount, dtos);
|
|
}
|
|
|
|
public virtual async Task<CommentWithAuthorDto> GetAsync(Guid id)
|
|
{
|
|
var comment = await CommentRepository.GetWithAuthorAsync(id);
|
|
|
|
var dto = ObjectMapper.Map<Comment, CommentWithAuthorDto>(comment.Comment);
|
|
dto.Author = ObjectMapper.Map<CmsUser, CmsUserDto>(comment.Author);
|
|
|
|
return dto;
|
|
}
|
|
|
|
[Authorize(CmsKitAdminPermissions.Comments.Delete)]
|
|
public virtual async Task DeleteAsync(Guid id)
|
|
{
|
|
var comment = await CommentRepository.GetAsync(id);
|
|
await CommentRepository.DeleteWithRepliesAsync(comment);
|
|
}
|
|
|
|
[Authorize(CmsKitAdminPermissions.Comments.Update)]
|
|
public async Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto input)
|
|
{
|
|
var comment = await CommentRepository.GetAsync(id);
|
|
comment.SetApprovalStatus(input.IsApproved);
|
|
|
|
await CommentRepository.UpdateAsync(comment);
|
|
}
|
|
|
|
[Authorize(CmsKitAdminPermissions.Comments.Update)]
|
|
public async Task SetSettingsAsync(CommentSettingsDto input)
|
|
{
|
|
await SettingManager.SetGlobalAsync(AppSettings.CommentRequireApprovement, input.CommentRequireApprovement.ToString());
|
|
}
|
|
|
|
public async Task<CommentSettingsDto> GetSettingsAsync()
|
|
{
|
|
var isRequireApprovementEnabled = bool.Parse(await SettingManager.GetOrNullGlobalAsync(AppSettings.CommentRequireApprovement));
|
|
|
|
return new CommentSettingsDto
|
|
{
|
|
CommentRequireApprovement = isRequireApprovementEnabled
|
|
};
|
|
}
|
|
|
|
public async Task<int> GetWaitingCountAsync()
|
|
{
|
|
return (int) await CommentRepository.GetCountAsync(commentApproveState: CommentApproveState.Waiting);
|
|
}
|
|
}
|
|
|