Update models because contracts were removed

This commit is contained in:
2023-05-01 22:17:50 +02:00
parent 54aaf9fda0
commit c8f0537976
9 changed files with 77 additions and 103 deletions

View File

@ -4,13 +4,13 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models {
[Table("area_commitment"), PrimaryKey("VNr")]
[Table("area_commitment"), PrimaryKey("FbNr")]
public class AreaCom {
[Column("vnr")]
public int VNr { get; set; }
[Column("fbnr")]
public int FbNr { get; set; }
[Column("area")]
public int Area { get; set; }
[Column("mgnr")]
public int MgNr { get; set; }
[Column("sortid")]
public string SortId { get; set; }
@ -18,8 +18,29 @@ namespace Elwig.Models {
[Column("cultid")]
public string CultId { get; set; }
[ForeignKey("VNr")]
public virtual Contract Contract { get; private set; }
[Column("area")]
public int Area { get; set; }
[Column("kgnr")]
public int KgNr { get; set; }
[Column("gstnr")]
public 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; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[ForeignKey("SortId")]
public virtual WineVar WineVar { get; private set; }
@ -27,8 +48,11 @@ namespace Elwig.Models {
[ForeignKey("CultId")]
public virtual WineCult WineCult { get; private set; }
[InverseProperty("AreaCom")]
public virtual ISet<AreaComParcel> Parcels { get; private set; }
[ForeignKey("KgNr")]
public virtual WbKg Kg { get; private set; }
[ForeignKey("KgNr, RdNr")]
public virtual WbRd? Rd { get; private set; }
[InverseProperty("AreaCom")]
public virtual ISet<AreaComAttr> AttributeEntries { get; private set; }

View File

@ -2,15 +2,15 @@ using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("area_commitment_attribute"), PrimaryKey("VNr", "AttrId")]
[Table("area_commitment_attribute"), PrimaryKey("FbNr", "AttrId")]
public class AreaComAttr {
[Column("vnr")]
public int VNr { get; set; }
[Column("fbnr")]
public int FbNr { get; set; }
[Column("attrid")]
public string AttrId { get; set; }
[ForeignKey("VNr")]
[ForeignKey("FbNr")]
public virtual AreaCom AreaCom { get; private set; }
[ForeignKey("AttrId")]

View File

@ -1,31 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("area_commitment_parcel"), PrimaryKey("VNr", "KgNr", "GstNr")]
public class AreaComParcel {
[Column("vnr")]
public int VNr { get; set; }
[Column("kgnr")]
public int KgNr { get; set; }
[Column("gstnr")]
public string? GstNr { get; set; }
[Column("rdnr")]
public int? RdNr { get; set; }
[Column("area")]
public int? Area { get; set; }
[ForeignKey("KgNr")]
public virtual WbKg Kg { get; private set; }
[ForeignKey("KgNr, RdNr")]
public virtual WbRd? Rd { get; private set; }
[ForeignKey("VNr")]
public virtual AreaCom AreaCom { get; private set; }
}
}

View File

@ -1,45 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("contract"), PrimaryKey("VNr")]
public class Contract {
[Column("vnr")]
public int VNr { get; set; }
[Column("mgnr")]
public int MgNr { get; set; }
[Column("date")]
public string? DateString { get; set; }
[NotMapped]
public DateOnly? Date {
get {
return DateString != null ? DateOnly.ParseExact(DateString, "yyyy-MM-dd") : null;
}
set {
DateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("year_from")]
public int YearFrom { get; set; }
[Column("year_to")]
public int? YearTo { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[InverseProperty("Contract")]
public virtual AreaCom? AreaCom { get; private set; }
[NotMapped]
public int? Area => AreaCom?.Area;
}
}

View File

@ -162,10 +162,10 @@ namespace Elwig.Models {
public virtual Branch? Branch { get; private set; }
[InverseProperty("Member")]
public virtual ISet<Contract> Contracts { get; private set; }
public virtual ISet<AreaCom> AreaCommitments { get; private set; }
[NotMapped]
public virtual IEnumerable<Contract> ActiveContracts => Contracts
public virtual IEnumerable<AreaCom> ActiveAreaCommitments => AreaCommitments
.Where(c => c.YearFrom <= Utils.CurrentSeason && (c.YearTo ?? int.MaxValue) >= Utils.CurrentSeason);
[InverseProperty("Member")]