1- using Kentico . PageBuilder . Web . Mvc ;
1+ using CMS . DataEngine ;
2+ using Kentico . PageBuilder . Web . Mvc ;
23using Microsoft . AspNetCore . Html ;
34using Microsoft . AspNetCore . Mvc ;
45using Microsoft . AspNetCore . Mvc . ViewComponents ;
@@ -22,15 +23,18 @@ public class HeroBannerWidgetViewComponent : ViewComponent
2223{
2324 private readonly IContentItemRetrieverService contentItemRetrieverService ;
2425 private readonly IEnumStringService enumStringService ;
26+ private readonly IContentTypeService contentTypeService ;
2527
2628 public const string IDENTIFIER = "TrainingGuides.HeroBanner" ;
2729
2830 public HeroBannerWidgetViewComponent (
2931 IContentItemRetrieverService contentItemRetrieverService ,
30- IEnumStringService enumStringService )
32+ IEnumStringService enumStringService ,
33+ IContentTypeService contentTypeService )
3134 {
3235 this . contentItemRetrieverService = contentItemRetrieverService ;
3336 this . enumStringService = enumStringService ;
37+ this . contentTypeService = contentTypeService ;
3438 }
3539
3640 public async Task < ViewViewComponentResult > InvokeAsync ( HeroBannerWidgetProperties properties )
@@ -41,11 +45,13 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
4145 {
4246 var productPage = await contentItemRetrieverService . RetrieveCurrentPage < ProductPage > ( 3 ) ;
4347
44- if ( productPage != null )
48+ int ? productClassId = contentTypeService . GetContentTypeId ( ProductPage . CONTENT_TYPE_NAME ) ;
49+
50+ if ( productPage is not null && productPage . SystemFields . ContentItemContentTypeID == productClassId )
4551 {
4652 banner = GetProductPageBanner ( productPage ) ;
4753
48- if ( banner != null )
54+ if ( banner is not null )
4955 {
5056 banner . CTALink = properties . ProductPageAnchor ;
5157 banner . CTAText = properties . CTA ;
@@ -55,7 +61,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
5561 }
5662 else if ( string . Equals ( properties . Mode , "productPage" ) )
5763 {
58- if ( properties . ProductPage . FirstOrDefault ( ) != null )
64+ if ( properties . ProductPage . FirstOrDefault ( ) is not null )
5965 {
6066 var productPageGuid = properties . ProductPage ? . Select ( i => i . Identifier ) . FirstOrDefault ( ) ;
6167 var productPage = productPageGuid . HasValue
@@ -64,7 +70,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
6470 : null ;
6571
6672 banner = GetProductPageBanner ( productPage ) ;
67- if ( banner != null )
73+ if ( banner is not null )
6874 {
6975 string relativeUrl = productPage ? . SystemFields . WebPageUrlPath is not null
7076 ? $ "~/{ productPage . SystemFields . WebPageUrlPath } "
@@ -78,7 +84,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
7884 }
7985 else
8086 {
81- if ( properties . Hero != null && properties . Hero . Any ( ) )
87+ if ( properties . Hero is not null && properties . Hero . Any ( ) )
8288 {
8389 var heroGuid = properties ? . Hero ? . Select ( i => i . Identifier ) . ToList ( ) . FirstOrDefault ( ) ;
8490
@@ -89,7 +95,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
8995
9096 banner = GetModel ( hero , properties ) ;
9197
92- if ( banner ? . Link != null )
98+ if ( banner ? . Link is not null )
9399 {
94100 banner . CTALink = ! string . IsNullOrEmpty ( banner . Link . LinkUrl ) ? banner ! . Link . LinkUrl : banner . Link . LinkToExternal ?? string . Empty ;
95101 banner . CTAText = ! string . IsNullOrEmpty ( properties ? . CTA ) ? properties . CTA : banner . Link . CallToAction ;
@@ -98,7 +104,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
98104 }
99105 }
100106
101- if ( banner != null )
107+ if ( banner is not null )
102108 {
103109
104110 banner . DisplayCTA = ! string . IsNullOrEmpty ( banner . CTALink ) && ! string . IsNullOrEmpty ( banner . CTAText ) && properties ! . DisplayCTA ;
@@ -135,13 +141,13 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
135141 }
136142
137143 private HeroBannerWidgetViewModel ? GetProductPageBanner ( ProductPage ? productPage ) =>
138- productPage == null ? null : GetHeroBannerViewModel ( productPage ) ;
144+ productPage is null ? null : GetHeroBannerViewModel ( productPage ) ;
139145
140146 private static HeroBannerWidgetViewModel ? GetHeroBannerViewModel ( ProductPage productPage )
141147 {
142148 var product = productPage . ProductPageProduct . FirstOrDefault ( ) ;
143149
144- if ( product != null )
150+ if ( product is not null )
145151 {
146152 var benefits = product . ProductBenefits . ToList ( ) ;
147153 var media = product . ProductMedia . FirstOrDefault ( ) ;
@@ -151,7 +157,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
151157 Header = product . ProductName ,
152158 SubheaderHtml = new HtmlString ( product . ProductShortDescription ) ,
153159 Benefits = benefits . Select ( BenefitViewModel . GetViewModel ) . ToList ( ) ,
154- Media = media != null
160+ Media = media is not null
155161 ? AssetViewModel . GetViewModel ( media )
156162 : new AssetViewModel ( )
157163 } ;
@@ -162,7 +168,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
162168
163169 private HeroBannerWidgetViewModel ? GetModel ( Hero ? hero , HeroBannerWidgetProperties ? properties )
164170 {
165- if ( hero == null || properties == null )
171+ if ( hero is null || properties is null )
166172 {
167173 return null ;
168174 }
@@ -181,7 +187,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
181187 LinkUrl = url ? . RelativePath ?? string . Empty ,
182188 CallToAction = hero . HeroCallToAction
183189 } ,
184- Media = media != null
190+ Media = media is not null
185191 ? AssetViewModel . GetViewModel ( media )
186192 : new AssetViewModel ( )
187193 } ;
0 commit comments