mirror of https://github.com/abpframework/abp.git
10 changed files with 171 additions and 2 deletions
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public class ContentDto : EntityDto<Guid> |
|||
{ |
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public interface IContentAppService |
|||
{ |
|||
Task<ContentDto> GetAsync(string entityType, string entityId); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using AutoMapper; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Common.Application.Volo.CmsKit |
|||
{ |
|||
public class CmsKitCommonApplicationAutoMapperProfile : Profile |
|||
{ |
|||
public CmsKitCommonApplicationAutoMapperProfile() |
|||
{ |
|||
CreateMap<Content, ContentDto>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public class ContentAppService : CmsKitAppServiceBase, IContentAppService |
|||
{ |
|||
private readonly IContentRepository _contentRepository; |
|||
|
|||
public ContentAppService(IContentRepository contentRepository) |
|||
{ |
|||
_contentRepository = contentRepository; |
|||
} |
|||
|
|||
public async Task<ContentDto> GetAsync(string entityType, string entityId) |
|||
{ |
|||
var entity = await _contentRepository.FindAsync(entityType, entityId); // Tenant???
|
|||
|
|||
return ObjectMapper.Map<Content, ContentDto>(entity); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
using Volo.CmsKit.Contents; |
|||
using Volo.CmsKit.Web.Contents; |
|||
|
|||
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents |
|||
{ |
|||
[ViewComponent(Name = "CmsContent")] |
|||
public class ContentViewComponent : AbpViewComponent |
|||
{ |
|||
private readonly IContentRenderer contentRenderer; |
|||
private readonly IContentAppService contentAppService; |
|||
|
|||
public ContentViewComponent( |
|||
IContentRenderer contentRenderer, |
|||
IContentAppService contentAppService) |
|||
{ |
|||
this.contentRenderer = contentRenderer; |
|||
this.contentAppService = contentAppService; |
|||
} |
|||
|
|||
public virtual async Task<IViewComponentResult> InvokeAsync( |
|||
string entityType, |
|||
string entityId) |
|||
{ |
|||
var content = await contentAppService.GetAsync(entityType, entityId); |
|||
var viewModel = new ContentViewModel |
|||
{ |
|||
EntityId = entityId, |
|||
EntityType = entityType, |
|||
ContentId = content.Id, |
|||
Rendered = await contentRenderer.RenderAsync(content.Value) |
|||
}; |
|||
|
|||
return View("~/Pages/CmsKit/Shared/Components/Contents/Default.cshtml", viewModel); |
|||
} |
|||
|
|||
public class ContentViewModel |
|||
{ |
|||
public Guid ContentId { get; set; } |
|||
public string EntityType { get; set; } |
|||
|
|||
public string EntityId { get; set; } |
|||
|
|||
public string Rendered { get; set; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
@using Microsoft.AspNetCore.Mvc.Localization |
|||
@using Volo.CmsKit.Localization |
|||
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents |
|||
@model ContentViewComponent.ContentViewModel |
|||
|
|||
<div> |
|||
@Html.Raw(Model.Rendered) |
|||
</div> |
|||
@ -1,10 +1,17 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public interface IContentRepository : IBasicRepository<Content, Guid> |
|||
{ |
|||
|
|||
Task<Content> FindAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue