Skip to content

Commit

Permalink
GH-69 :: refactor, include nullable for featured article view model
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-matthews committed Aug 29, 2024
1 parent 58a0713 commit 9d0d5ea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<field allowempty="true" column="ArticlePageArticleContent" columnprecision="0" columntype="contentitemreference" enabled="true" guid="b660d800-8f44-4311-af7d-f5073bda6ab3" visible="true">
<properties>
<explanationtextashtml>False</explanationtextashtml>
<fieldcaption>Content</fieldcaption>
<fieldcaption>Article page content</fieldcaption>
<fielddescriptionashtml>False</fielddescriptionashtml>
</properties>
<settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@model TrainingGuides.Web.Features.Articles.Widgets.FeaturedArticle.FeaturedArticleWidgetViewModel?

@if (Model is null || Model.IsMisconfigured || Model.Article is null )
@if (Model is null || Model.IsMisconfigured)
{
<tg-page-builder-content>
<div class="c-card md bg-1 u-border-02 text-center">
Expand All @@ -14,7 +14,7 @@
else
{
<div class="c-card md bg-1 u-border-02 text-center mt-4">
@if (Model.Article.TeaserImage != null)
@if (Model.Article!.TeaserImage != null)
{
<img src="@Url.Content(Model.Article.TeaserImage.FilePath)" alt="@Model.Article.TeaserImage.AltText" class="u-border-02 img-fluid" />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public async Task<ViewViewComponentResult> InvokeAsync(FeaturedArticleWidgetProp
guid.Value,
ArticlePage.CONTENT_TYPE_NAME,
3)
: new ArticlePage();
: null;

var model = articlePage != null
? new FeaturedArticleWidgetViewModel()
{
Article = await articlePageService.GetArticlePageViewModel(articlePage)
}
: new FeaturedArticleWidgetViewModel();
: null;

return View("~/Features/Articles/Widgets/FeaturedArticle/FeaturedArticleWidget.cshtml", model);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ namespace TrainingGuides.Web.Features.Articles.Widgets.FeaturedArticle;

public class FeaturedArticleWidgetViewModel : WidgetViewModel
{
public ArticlePageViewModel Article { get; set; } = new ArticlePageViewModel();
public ArticlePageViewModel? Article { get; set; }

public override bool IsMisconfigured => string.IsNullOrWhiteSpace(Article.Title)
|| string.IsNullOrWhiteSpace(Article.Summary.ToString())
|| Article.TeaserImage == null
|| string.IsNullOrWhiteSpace(Article.Url);
public override bool IsMisconfigured => Article == null;
}

0 comments on commit 9d0d5ea

Please sign in to comment.