[#77] Entities: Add AreaComContract to group area commitments together
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
using Elwig.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Elwig.Models.Entities {
|
||||
[Table("area_commitment"), PrimaryKey("FbNr")]
|
||||
[Table("area_commitment"), PrimaryKey("FbNr", "RevNr")]
|
||||
public class AreaCom {
|
||||
[Column("fbnr")]
|
||||
public int FbNr { get; set; }
|
||||
|
||||
[Column("revnr")]
|
||||
public int RevNr { get; set; }
|
||||
|
||||
[Column("mgnr")]
|
||||
public int MgNr { get; set; }
|
||||
|
||||
@@ -22,24 +23,15 @@ namespace Elwig.Models.Entities {
|
||||
[Column("area")]
|
||||
public int Area { get; set; }
|
||||
|
||||
[Column("kgnr")]
|
||||
public int KgNr { get; set; }
|
||||
|
||||
[Column("gstnr")]
|
||||
public required string GstNr { get; set; }
|
||||
|
||||
[Column("rdnr")]
|
||||
public int? RdNr { get; set; }
|
||||
|
||||
[Column("year_from")]
|
||||
public int? YearFrom { get; set; }
|
||||
|
||||
[Column("year_to")]
|
||||
public int? YearTo { get; set; }
|
||||
|
||||
[Column("comment")]
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[Column("ctime"), DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
public long CTime { get; set; }
|
||||
[NotMapped]
|
||||
@@ -72,6 +64,9 @@ namespace Elwig.Models.Entities {
|
||||
set => ITime = value == null ? null : ((DateTimeOffset)value.Value.ToUniversalTime()).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
[ForeignKey("FbNr")]
|
||||
public virtual AreaComContract Contract { get; private set; } = null!;
|
||||
|
||||
[ForeignKey("MgNr")]
|
||||
public virtual Member Member { get; private set; } = null!;
|
||||
|
||||
@@ -80,17 +75,5 @@ namespace Elwig.Models.Entities {
|
||||
|
||||
[ForeignKey("CultId")]
|
||||
public virtual WineCult? WineCult { get; private set; }
|
||||
|
||||
[ForeignKey("KgNr")]
|
||||
public virtual WbKg Kg { get; private set; } = null!;
|
||||
|
||||
[ForeignKey("KgNr, RdNr")]
|
||||
public virtual WbRd? Rd { get; private set; }
|
||||
|
||||
public int SearchScore(IEnumerable<string> keywords) {
|
||||
return Utils.GetSearchScore([
|
||||
WineCult?.Name, Kg.AtKg.Name, Rd?.Name, GstNr, Comment,
|
||||
], keywords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
78
Elwig/Models/Entities/AreaComContract.cs
Normal file
78
Elwig/Models/Entities/AreaComContract.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Elwig.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Models.Entities {
|
||||
[Table("area_commitment_contract"), PrimaryKey("FbNr")]
|
||||
public class AreaComContract {
|
||||
[Column("fbnr")]
|
||||
public int FbNr { get; set; }
|
||||
|
||||
[Column("kgnr")]
|
||||
public int KgNr { get; set; }
|
||||
|
||||
[Column("rdnr")]
|
||||
public int? RdNr { get; set; }
|
||||
|
||||
[Column("comment")]
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[Column("ctime"), DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
public long CTime { get; set; }
|
||||
[NotMapped]
|
||||
public DateTime CreatedAt {
|
||||
get => DateTimeOffset.FromUnixTimeSeconds(CTime).LocalDateTime;
|
||||
set => CTime = ((DateTimeOffset)value.ToUniversalTime()).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
[Column("mtime"), DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
public long MTime { get; set; }
|
||||
[NotMapped]
|
||||
public DateTime ModifiedAt {
|
||||
get => DateTimeOffset.FromUnixTimeSeconds(MTime).LocalDateTime;
|
||||
set => MTime = ((DateTimeOffset)value.ToUniversalTime()).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
[Column("xtime")]
|
||||
public long? XTime { get; set; }
|
||||
[NotMapped]
|
||||
public DateTime? ExportedAt {
|
||||
get => XTime == null ? null : DateTimeOffset.FromUnixTimeSeconds(XTime.Value).LocalDateTime;
|
||||
set => XTime = value == null ? null : ((DateTimeOffset)value.Value.ToUniversalTime()).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
[Column("itime")]
|
||||
public long? ITime { get; set; }
|
||||
[NotMapped]
|
||||
public DateTime? ImportedAt {
|
||||
get => ITime == null ? null : DateTimeOffset.FromUnixTimeSeconds(ITime.Value).LocalDateTime;
|
||||
set => ITime = value == null ? null : ((DateTimeOffset)value.Value.ToUniversalTime()).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
[ForeignKey("KgNr")]
|
||||
public virtual WbKg Kg { get; private set; } = null!;
|
||||
|
||||
[ForeignKey("KgNr, RdNr")]
|
||||
public virtual WbRd? Rd { get; private set; }
|
||||
|
||||
[InverseProperty(nameof(AreaCom.Contract))]
|
||||
public virtual ICollection<AreaCom> Revisions { get; private set; } = null!;
|
||||
|
||||
[NotMapped]
|
||||
public AreaCom? Latest => Revisions.OrderBy(r => r.RevNr).LastOrDefault();
|
||||
|
||||
[NotMapped]
|
||||
public int? YearFrom => Revisions.Any(r => r.YearFrom == null) ? null : Revisions.Min(r => r.YearFrom);
|
||||
[NotMapped]
|
||||
public int? YearTo => Revisions.Any(r => r.YearTo == null) ? null : Revisions.Max(r => r.YearTo);
|
||||
|
||||
public int SearchScore(IEnumerable<string> keywords) {
|
||||
return Utils.GetSearchScore([
|
||||
..Revisions.Select(r => r.WineCult?.Name), Kg.AtKg.Name, Rd?.Name, ..Revisions.Select(r => r.GstNr), Comment,
|
||||
], keywords);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user