|
|
|
@ -4,6 +4,7 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.CmsKit.Permissions; |
|
|
|
@ -12,39 +13,27 @@ using Volo.CmsKit.Tags; |
|
|
|
namespace Volo.CmsKit.Admin.Tags |
|
|
|
{ |
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
|
|
|
public class TagAdminAppService : |
|
|
|
CrudAppService< |
|
|
|
Tag, |
|
|
|
TagDto, |
|
|
|
Guid, |
|
|
|
TagGetListInput, |
|
|
|
TagCreateDto, |
|
|
|
TagUpdateDto>, |
|
|
|
ITagAdminAppService |
|
|
|
public class TagAdminAppService : CmsKitAppServiceBase, ITagAdminAppService |
|
|
|
{ |
|
|
|
protected ITagRepository Repository { get; } |
|
|
|
protected TagManager TagManager { get; } |
|
|
|
protected ITagDefinitionStore TagDefinitionStore { get; } |
|
|
|
protected IStringLocalizerFactory StringLocalizerFactory { get; } |
|
|
|
|
|
|
|
public TagAdminAppService( |
|
|
|
IRepository<Tag, Guid> repository, |
|
|
|
ITagRepository repository, |
|
|
|
TagManager tagManager, |
|
|
|
ITagDefinitionStore tagDefinitionStore, |
|
|
|
IStringLocalizerFactory stringLocalizerFactory) : base(repository) |
|
|
|
IStringLocalizerFactory stringLocalizerFactory) |
|
|
|
{ |
|
|
|
Repository = repository; |
|
|
|
TagManager = tagManager; |
|
|
|
TagDefinitionStore = tagDefinitionStore; |
|
|
|
StringLocalizerFactory = stringLocalizerFactory; |
|
|
|
|
|
|
|
GetListPolicyName = CmsKitAdminPermissions.Tags.Default; |
|
|
|
GetPolicyName = CmsKitAdminPermissions.Tags.Default; |
|
|
|
CreatePolicyName = CmsKitAdminPermissions.Tags.Create; |
|
|
|
UpdatePolicyName = CmsKitAdminPermissions.Tags.Update; |
|
|
|
DeletePolicyName = CmsKitAdminPermissions.Tags.Delete; |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Create)] |
|
|
|
public override async Task<TagDto> CreateAsync(TagCreateDto input) |
|
|
|
public async Task<TagDto> CreateAsync(TagCreateDto input) |
|
|
|
{ |
|
|
|
var tag = await TagManager.CreateAsync( |
|
|
|
GuidGenerator.Create(), |
|
|
|
@ -53,11 +42,11 @@ namespace Volo.CmsKit.Admin.Tags |
|
|
|
|
|
|
|
await Repository.InsertAsync(tag); |
|
|
|
|
|
|
|
return await MapToGetOutputDtoAsync(tag); |
|
|
|
return ObjectMapper.Map<Tag, TagDto>(tag); |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Update)] |
|
|
|
public override async Task<TagDto> UpdateAsync(Guid id, TagUpdateDto input) |
|
|
|
public async Task<TagDto> UpdateAsync(Guid id, TagUpdateDto input) |
|
|
|
{ |
|
|
|
var tag = await TagManager.UpdateAsync( |
|
|
|
id, |
|
|
|
@ -65,31 +54,48 @@ namespace Volo.CmsKit.Admin.Tags |
|
|
|
|
|
|
|
await Repository.UpdateAsync(tag); |
|
|
|
|
|
|
|
return await MapToGetOutputDtoAsync(tag); |
|
|
|
} |
|
|
|
|
|
|
|
protected override async Task<IQueryable<Tag>> CreateFilteredQueryAsync(TagGetListInput input) |
|
|
|
{ |
|
|
|
return (await base.CreateFilteredQueryAsync(input)) |
|
|
|
.WhereIf( |
|
|
|
!input.Filter.IsNullOrEmpty(), |
|
|
|
x => |
|
|
|
x.Name.ToLower().Contains(input.Filter) || |
|
|
|
x.EntityType.ToLower().Contains(input.Filter)); |
|
|
|
return ObjectMapper.Map<Tag, TagDto>(tag); |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
|
|
|
public virtual async Task<List<TagDefinitionDto>> GetTagDefinitionsAsync() |
|
|
|
{ |
|
|
|
var definitions = await TagDefinitionStore.GetTagEntityTypeDefinitionListAsync(); |
|
|
|
|
|
|
|
return definitions |
|
|
|
.Select(s => |
|
|
|
.Select(s => |
|
|
|
new TagDefinitionDto |
|
|
|
{ |
|
|
|
EntityType = s.EntityType, |
|
|
|
EntityType = s.EntityType, |
|
|
|
DisplayName = s.DisplayName?.Localize(StringLocalizerFactory) ?? s.EntityType |
|
|
|
}) |
|
|
|
.ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
|
|
|
public async Task<TagDto> GetAsync(Guid id) |
|
|
|
{ |
|
|
|
var tag = await Repository.GetAsync(id); |
|
|
|
|
|
|
|
return ObjectMapper.Map<Tag, TagDto>(tag); |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
|
|
|
public async Task<PagedResultDto<TagDto>> GetListAsync(TagGetListInput input) |
|
|
|
{ |
|
|
|
var tags = await Repository.GetListAsync(input.Filter); |
|
|
|
var count = await Repository.GetCountAsync(input.Filter); |
|
|
|
|
|
|
|
return new PagedResultDto<TagDto>( |
|
|
|
count, |
|
|
|
ObjectMapper.Map<List<Tag>, List<TagDto>>(tags) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
[Authorize(CmsKitAdminPermissions.Tags.Delete)] |
|
|
|
public async Task DeleteAsync(Guid id) |
|
|
|
{ |
|
|
|
await Repository.DeleteAsync(id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|