From 5cbc145271889e32f5ff5ecda4088d4605aa029d Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 26 Jul 2022 18:32:24 +0300 Subject: [PATCH] Decreased the duplication --- .../Volo/CmsKit/Contents/IContent.cs | 7 +++++++ .../Volo/CmsKit/Contents/PageDto.cs | 2 +- .../Contents/ContentFragment.cshtml | 2 +- .../Contents/ContentFragmentViewComponent.cs | 16 ++++++---------- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContent.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContent.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContent.cs new file mode 100644 index 0000000000..2a393e0a14 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContent.cs @@ -0,0 +1,7 @@ +using System.Collections.Generic; + +namespace Volo.CmsKit.Contents; +public interface IContent +{ + public List ContentFragments { get; set; } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/PageDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/PageDto.cs index 996a867fcf..0b573be372 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/PageDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/PageDto.cs @@ -5,7 +5,7 @@ using Volo.Abp.Application.Dtos; namespace Volo.CmsKit.Contents; [Serializable] -public class PageDto : EntityDto +public class PageDto : EntityDto, IContent { public string Title { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml index 994660600a..f0dce03b75 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml @@ -7,7 +7,7 @@ @inject IMarkdownToHtmlRenderer MarkdownRenderer -@foreach (var contentFragment in Model.PageDto.ContentFragments) +@foreach (var contentFragment in Model.ContentDto.ContentFragments) { if (contentFragment.Type == "Markdown") { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs index e6b7004940..6deeb90e22 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs @@ -1,26 +1,22 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.CmsKit.Contents; namespace Volo.CmsKit.Web.Contents; +[ViewComponent(Name = "ContentFragment")] [Widget( AutoInitialize = true )] -[ViewComponent(Name = "ContentFragment")] -public class ContentFragmentViewComponent : ViewComponent +public class ContentFragmentViewComponent : AbpViewComponent { - public PageDto PageDto { get; set; } - - public ContentFragmentViewComponent() - { - PageDto = new(); - } + public IContent ContentDto { get; set; } - public virtual async Task InvokeAsync(PageDto pageDto) + public virtual async Task InvokeAsync(IContent contentDto) { - return View("~/Contents/ContentFragment.cshtml", new ContentFragmentViewComponent() { PageDto = pageDto }); + return View("~/Contents/ContentFragment.cshtml", new ContentFragmentViewComponent() { ContentDto = contentDto }); } }