79 lines
2.9 KiB
C#
79 lines
2.9 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|