mirror of https://github.com/abpframework/abp.git
21 changed files with 290 additions and 19 deletions
@ -0,0 +1,12 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class CheckUrlInputDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] |
|||
public string Url { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class CreatePageInputDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))] |
|||
public string Title { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] |
|||
public string Url { get; set; } |
|||
|
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] |
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class CreatePageWithContentInputDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))] |
|||
public string Title { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] |
|||
public string Url { get; set; } |
|||
|
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] |
|||
public string Description { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxValueLength))] |
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public interface IPageAppService |
|||
{ |
|||
Task<PageDto> CreatePageAsync(CreatePageInputDto input); |
|||
|
|||
Task<PageDto> CreatePageWithContentAsync(CreatePageWithContentInputDto input); |
|||
|
|||
Task<PageDto> UpdatePageAsync(Guid id, UpdatePageInputDto input); |
|||
|
|||
Task<bool> DoesUrlExistAsync(CheckUrlInputDto input); |
|||
|
|||
Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input); |
|||
|
|||
Task DeletePageAsync(Guid id); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PageDto : EntityDto<Guid> |
|||
{ |
|||
public string Title { get; set; } |
|||
|
|||
public string Url { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PageWithContentDto : EntityDto<Guid> |
|||
{ |
|||
public string Title { get; set; } |
|||
|
|||
public string Url { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public ContentDto Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class UpdatePageContentInputDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxValueLength))] |
|||
public string Content { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class UpdatePageInputDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))] |
|||
public string Title { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] |
|||
public string Url { get; set; } |
|||
|
|||
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] |
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PageAppService : CmsKitAppServiceBase, IPageAppService |
|||
{ |
|||
protected readonly IPageRepository PageRepository; |
|||
protected readonly IContentRepository ContentRepository; |
|||
|
|||
public PageAppService(IPageRepository pageRepository, IContentRepository contentRepository) |
|||
{ |
|||
PageRepository = pageRepository; |
|||
ContentRepository = contentRepository; |
|||
} |
|||
|
|||
public virtual async Task<PageDto> CreatePageAsync(CreatePageInputDto input) |
|||
{ |
|||
var page = await CreatePageAsync(input.Title, input.Url, input.Description); |
|||
|
|||
await PageRepository.InsertAsync(page); |
|||
|
|||
return ObjectMapper.Map<Page, PageDto>(page); |
|||
} |
|||
|
|||
public virtual async Task<PageDto> CreatePageWithContentAsync(CreatePageWithContentInputDto input) |
|||
{ |
|||
var page = await CreatePageAsync(input.Title, input.Url, input.Description); |
|||
|
|||
await PageRepository.InsertAsync(page); |
|||
|
|||
var content = new Content( |
|||
GuidGenerator.Create(), |
|||
nameof(Page), |
|||
page.Id.ToString(), |
|||
input.Content, |
|||
page.TenantId); |
|||
|
|||
await ContentRepository.InsertAsync(content); |
|||
|
|||
return ObjectMapper.Map<Page, PageDto>(page); |
|||
} |
|||
|
|||
public virtual async Task<PageDto> UpdatePageAsync(Guid id, UpdatePageInputDto input) |
|||
{ |
|||
var page = await PageRepository.GetAsync(id); |
|||
|
|||
if (page.Url != input.Url) |
|||
{ |
|||
await CheckPageUrlAsync(input.Url); |
|||
} |
|||
|
|||
page.Title = input.Title; |
|||
page.Url = input.Url; |
|||
page.Description = input.Description; |
|||
|
|||
await PageRepository.UpdateAsync(page); |
|||
|
|||
return ObjectMapper.Map<Page, PageDto>(page); |
|||
} |
|||
|
|||
public virtual Task<bool> DoesUrlExistAsync(CheckUrlInputDto input) |
|||
{ |
|||
return PageRepository.DoesExistAsync(input.Url); |
|||
} |
|||
|
|||
public virtual async Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input) |
|||
{ |
|||
var pageContent = await ContentRepository.GetAsync(nameof(Page), id.ToString()); |
|||
|
|||
pageContent.SetValue(input.Content); |
|||
|
|||
await ContentRepository.UpdateAsync(pageContent); |
|||
} |
|||
|
|||
public virtual async Task DeletePageAsync(Guid id) |
|||
{ |
|||
await ContentRepository.DeleteAsync(nameof(Page), id.ToString(), CurrentTenant?.Id, CancellationToken.None); |
|||
await PageRepository.DeleteAsync(id, cancellationToken: CancellationToken.None); |
|||
} |
|||
|
|||
protected virtual async Task<Page> CreatePageAsync(string title, string url, string description) |
|||
{ |
|||
await CheckPageUrlAsync(url); |
|||
|
|||
return new Page(GuidGenerator.Create(), title, url, description, CurrentTenant?.Id); |
|||
} |
|||
|
|||
protected virtual async Task CheckPageUrlAsync(string url) |
|||
{ |
|||
if (await PageRepository.DoesExistAsync(url)) |
|||
{ |
|||
throw new UserFriendlyException("Url exist"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +1,15 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public interface IPageRepository : IBasicRepository<Page, Guid> |
|||
{ |
|||
|
|||
Task<Page> GetByUrlAsync(string url); |
|||
|
|||
Task<Page> FindByUrlAsync(string url); |
|||
|
|||
Task<bool> DoesExistAsync(string url); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue