I18NCommander/I18N Commander/DataModel/Database/Section.cs
Thorsten Sommer 4c6f5b59f0
Bugfixes
- Added handling for DeepL exceptions
- Added debug logging for im- and exporting
- When executing the post script for the unique id migration, ensure
  that new id are generated, only when no id exists
- Fixed section export by loading references to parents
2023-02-11 21:22:25 +01:00

51 lines
1.6 KiB
C#

using System.ComponentModel.DataAnnotations;
using DataModel.Database.Common;
namespace DataModel.Database;
public sealed class Section
{
[Key]
public int Id { get; set; }
public Guid UniqueId { get; set; } = Guid.NewGuid();
public string Name { get; set; } = string.Empty;
public string DataKey { get; set; } = string.Empty;
public int Depth { get; set; } = 0;
public Section? Parent { get; set; }
public List<TextElement> TextElements { get; set; } = new();
internal DataContext.JsonUniqueId JsonUniqueId => new(this.DataKey, this.UniqueId, "Sec");
internal DataContext.JsonSection ToJsonSection(DataContext db)
{
db.LoadElementsAsync(this, n => n.Parent).GetAwaiter().GetResult();
if(this.Depth > 0 && this.Parent == null)
Console.WriteLine($"Found section with depth > 0 and parent is null ==> {this.JsonUniqueId}");
return new()
{
UniqueId = this.JsonUniqueId,
Name = this.Name,
DataKey = this.DataKey,
Depth = this.Depth,
ParentUniqueId = this.Parent?.JsonUniqueId ?? new DataContext.JsonUniqueId("null", Guid.Empty, "Sec"),
TextElements = this.TextElements.Select(n => n.JsonUniqueId).ToList()
};
}
internal static Section FromJsonSection(DataContext.JsonSection jsonSection) => new()
{
UniqueId = jsonSection.UniqueId.UniqueId,
Name = jsonSection.Name,
DataKey = jsonSection.DataKey,
Depth = jsonSection.Depth,
Parent = null,
TextElements = new(),
};
}