[#77] Entities: Add AreaComContract to group area commitments together
This commit is contained in:
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