-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix json import casing references (#1803)
- Loading branch information
Showing
13 changed files
with
414 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace BDMS.Models; | ||
|
||
/// <summary> | ||
/// An object that has a reference to a <see cref="Models.Casing"/>. | ||
/// </summary> | ||
public interface ICasingReference | ||
{ | ||
/// <summary> | ||
/// Gets or sets the ID of the casing in the join table. | ||
/// </summary> | ||
int? CasingId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the casing in the join table. | ||
/// </summary> | ||
Casing? Casing { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace BDMS.Models; | ||
|
||
internal static class ICasingReferenceExtensions | ||
{ | ||
/// <summary> | ||
/// Maps a single ICasingReference to its corresponding Casing from the dictionary. | ||
/// </summary> | ||
public static void MapCasing(this ICasingReference casingReference, Dictionary<int, Casing> casings) | ||
{ | ||
if (casingReference == null) return; | ||
|
||
casingReference.Casing = null; | ||
if (casingReference.CasingId.HasValue) | ||
{ | ||
if (casings.TryGetValue(casingReference.CasingId.Value, out var casing)) | ||
{ | ||
casingReference.Casing = casing; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException($"Casing with ID {casingReference.CasingId} not found."); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Maps a list of ICasingReference objects to their corresponding Casings from the dictionary. | ||
/// </summary> | ||
public static void MapCasings(this IEnumerable<ICasingReference> casingReferences, Dictionary<int, Casing> casings) | ||
{ | ||
if (casingReferences == null) return; | ||
|
||
foreach (var casingReference in casingReferences) | ||
{ | ||
casingReference.MapCasing(casings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.