From 5ad8a112b5ac8da5ffb03de95c258fc434927fa8 Mon Sep 17 00:00:00 2001 From: uahussain12 <“umar.hussain@and.digital”> Date: Thu, 25 Jan 2024 16:56:16 +0000 Subject: [PATCH] fix: handle textBodyDB entity being empty - possible fix --- .../Content/Interfaces/IHasRichText.cs | 2 +- .../Content/Models/TextBodyDbEntity.cs | 2 +- .../Content/Models/WarningComponentDbEntity.cs | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Dfe.PlanTech.Domain/Content/Interfaces/IHasRichText.cs b/src/Dfe.PlanTech.Domain/Content/Interfaces/IHasRichText.cs index f45790d97..a5f5e73ac 100644 --- a/src/Dfe.PlanTech.Domain/Content/Interfaces/IHasRichText.cs +++ b/src/Dfe.PlanTech.Domain/Content/Interfaces/IHasRichText.cs @@ -5,5 +5,5 @@ namespace Dfe.PlanTech.Domain.Content.Interfaces; public interface IHasRichText { public RichTextContentDbEntity RichText { get; set; } - public long RichTextId { get; } + public long? RichTextId { get; } } diff --git a/src/Dfe.PlanTech.Domain/Content/Models/TextBodyDbEntity.cs b/src/Dfe.PlanTech.Domain/Content/Models/TextBodyDbEntity.cs index 213f57d5c..6c6d5d16e 100644 --- a/src/Dfe.PlanTech.Domain/Content/Models/TextBodyDbEntity.cs +++ b/src/Dfe.PlanTech.Domain/Content/Models/TextBodyDbEntity.cs @@ -11,7 +11,7 @@ public class TextBodyDbEntity : ContentComponentDbEntity, ITextBody Warnings { get; set; } = new(); } \ No newline at end of file diff --git a/src/Dfe.PlanTech.Domain/Content/Models/WarningComponentDbEntity.cs b/src/Dfe.PlanTech.Domain/Content/Models/WarningComponentDbEntity.cs index e18ce54b9..f9dc30293 100644 --- a/src/Dfe.PlanTech.Domain/Content/Models/WarningComponentDbEntity.cs +++ b/src/Dfe.PlanTech.Domain/Content/Models/WarningComponentDbEntity.cs @@ -9,13 +9,20 @@ public class WarningComponentDbEntity : ContentComponentDbEntity, IWarningCompon public string TextId { get; set; } = null!; public TextBodyDbEntity Text { get; set; } = null!; - [NotMapped] + [NotMapped][DontCopyValue] public RichTextContentDbEntity RichText { - get => Text.RichText; - set => Text.RichText = value; + get => Text?.RichText; + set + { + if (Text != null) + { + Text.RichText = value; + } + } } - [NotMapped] - public long RichTextId => Text.RichTextId; + [NotMapped][DontCopyValue] + public long? RichTextId => Text?.RichTextId; + } \ No newline at end of file