Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"kentico.xperience.dbmanager": {
"version": "30.11.1",
"commands": [
"kentico-xperience-dbmanager"
],
"rollForward": false
}
}
}
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageVersion Include="kentico.xperience.webapp" Version="30.11.1" />
<PackageVersion Include="Kentico.Xperience.Core" Version="30.11.1" />
<PackageVersion Include="kentico.xperience.mjml" Version="30.11.1" />

<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="8.0.14" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Moq" Version="4.20.70" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Kentico.PageBuilder.Web.Mvc;
using CMS.DataEngine;
using Kentico.PageBuilder.Web.Mvc;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
Expand All @@ -22,15 +23,18 @@ public class HeroBannerWidgetViewComponent : ViewComponent
{
private readonly IContentItemRetrieverService contentItemRetrieverService;
private readonly IEnumStringService enumStringService;
private readonly IContentTypeService contentTypeService;

public const string IDENTIFIER = "TrainingGuides.HeroBanner";

public HeroBannerWidgetViewComponent(
IContentItemRetrieverService contentItemRetrieverService,
IEnumStringService enumStringService)
IEnumStringService enumStringService,
IContentTypeService contentTypeService)
{
this.contentItemRetrieverService = contentItemRetrieverService;
this.enumStringService = enumStringService;
this.contentTypeService = contentTypeService;
}

public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetProperties properties)
Expand All @@ -41,11 +45,13 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
{
var productPage = await contentItemRetrieverService.RetrieveCurrentPage<ProductPage>(3);

if (productPage != null)
int? productClassId = contentTypeService.GetContentTypeId(ProductPage.CONTENT_TYPE_NAME);

if (productPage is not null && productPage.SystemFields.ContentItemContentTypeID == productClassId)
{
banner = GetProductPageBanner(productPage);

if (banner != null)
if (banner is not null)
{
banner.CTALink = properties.ProductPageAnchor;
banner.CTAText = properties.CTA;
Expand All @@ -55,7 +61,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
}
else if (string.Equals(properties.Mode, "productPage"))
{
if (properties.ProductPage.FirstOrDefault() != null)
if (properties.ProductPage.FirstOrDefault() is not null)
{
var productPageGuid = properties.ProductPage?.Select(i => i.Identifier).FirstOrDefault();
var productPage = productPageGuid.HasValue
Expand All @@ -64,7 +70,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
: null;

banner = GetProductPageBanner(productPage);
if (banner != null)
if (banner is not null)
{
string relativeUrl = productPage?.SystemFields.WebPageUrlPath is not null
? $"~/{productPage.SystemFields.WebPageUrlPath}"
Expand All @@ -78,7 +84,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
}
else
{
if (properties.Hero != null && properties.Hero.Any())
if (properties.Hero is not null && properties.Hero.Any())
{
var heroGuid = properties?.Hero?.Select(i => i.Identifier).ToList().FirstOrDefault();

Expand All @@ -89,7 +95,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie

banner = GetModel(hero, properties);

if (banner?.Link != null)
if (banner?.Link is not null)
{
banner.CTALink = !string.IsNullOrEmpty(banner.Link.LinkUrl) ? banner!.Link.LinkUrl : banner.Link.LinkToExternal ?? string.Empty;
banner.CTAText = !string.IsNullOrEmpty(properties?.CTA) ? properties.CTA : banner.Link.CallToAction;
Expand All @@ -98,7 +104,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
}
}

if (banner != null)
if (banner is not null)
{

banner.DisplayCTA = !string.IsNullOrEmpty(banner.CTALink) && !string.IsNullOrEmpty(banner.CTAText) && properties!.DisplayCTA;
Expand Down Expand Up @@ -135,13 +141,13 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
}

private HeroBannerWidgetViewModel? GetProductPageBanner(ProductPage? productPage) =>
productPage == null ? null : GetHeroBannerViewModel(productPage);
productPage is null ? null : GetHeroBannerViewModel(productPage);

private static HeroBannerWidgetViewModel? GetHeroBannerViewModel(ProductPage productPage)
{
var product = productPage.ProductPageProduct.FirstOrDefault();

if (product != null)
if (product is not null)
{
var benefits = product.ProductBenefits.ToList();
var media = product.ProductMedia.FirstOrDefault();
Expand All @@ -151,7 +157,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
Header = product.ProductName,
SubheaderHtml = new HtmlString(product.ProductShortDescription),
Benefits = benefits.Select(BenefitViewModel.GetViewModel).ToList(),
Media = media != null
Media = media is not null
? AssetViewModel.GetViewModel(media)
: new AssetViewModel()
};
Expand All @@ -162,7 +168,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie

private HeroBannerWidgetViewModel? GetModel(Hero? hero, HeroBannerWidgetProperties? properties)
{
if (hero == null || properties == null)
if (hero is null || properties is null)
{
return null;
}
Expand All @@ -181,7 +187,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
LinkUrl = url?.RelativePath ?? string.Empty,
CallToAction = hero.HeroCallToAction
},
Media = media != null
Media = media is not null
? AssetViewModel.GetViewModel(media)
: new AssetViewModel()
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CMS.DataEngine;
using CMS.Helpers;
using Kentico.PageBuilder.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -31,15 +32,18 @@ public class ProductWidgetViewComponent : ViewComponent
private readonly IContentItemRetrieverService contentItemRetrieverService;
private readonly IComponentStyleEnumService componentStyleEnumService;
private readonly IProductPageService productPageService;
private readonly IContentTypeService contentTypeService;

public ProductWidgetViewComponent(
IContentItemRetrieverService contentItemRetrieverService,
IComponentStyleEnumService componentStyleEnumService,
IProductPageService productPageService)
IProductPageService productPageService,
IContentTypeService contentTypeService)
{
this.contentItemRetrieverService = contentItemRetrieverService;
this.componentStyleEnumService = componentStyleEnumService;
this.productPageService = productPageService;
this.contentTypeService = contentTypeService;
}

public async Task<ViewViewComponentResult> InvokeAsync(ProductWidgetProperties properties)
Expand Down Expand Up @@ -94,8 +98,13 @@ private async Task<ProductWidgetViewModel> GetProductWidgetViewModel(ProductWidg
: null;
}

return productPage;
int? productContentTypeId = contentTypeService.GetContentTypeId(ProductPage.CONTENT_TYPE_NAME);

return productPage?.SystemFields.ContentItemContentTypeID == productContentTypeId
? productPage
: null;
}

private async Task<ProductPageViewModel?> GetProductPageViewModel(ProductWidgetProperties properties)
{
var productPage = await GetProductPage(properties);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CMS.DataEngine;

namespace TrainingGuides.Web.Features.Shared.Services;

public class ContentTypeService : IContentTypeService
{
/// <summary>
/// Gets the content type ID for a given content type name.
/// </summary>
/// <param name="contentTypeName"></param>
/// <returns>Content type ID of provided content type, null if not found</returns>
public int? GetContentTypeId(string contentTypeName) =>
DataClassInfoProvider
.GetDataClassInfo(contentTypeName)?
.ClassID;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TrainingGuides.Web.Features.Shared.Services;

public interface IContentTypeService
{
/// <summary>
/// Gets the content type ID for a given content type name.
/// </summary>
/// <param name="contentTypeName"></param>
/// <returns>Content type ID of provided content type, null if not found</returns>
int? GetContentTypeId(string contentTypeName);
}
1 change: 1 addition & 0 deletions src/TrainingGuides.Web/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class ServiceCollectionExtensions
{
public static void AddTrainingGuidesServices(this IServiceCollection services)
{
services.AddSingleton<IContentTypeService, ContentTypeService>();
services.AddSingleton<IStringEncryptionService, AesEncryptionService>();
services.AddSingleton<IFormCollectionService, FormCollectionService>();
services.AddSingleton<ICookieConsentService, CookieConsentService>();
Expand Down
Loading