diff --git a/Elwig/Helpers/AppDbContext.cs b/Elwig/Helpers/AppDbContext.cs index 2225e94..50519cb 100644 --- a/Elwig/Helpers/AppDbContext.cs +++ b/Elwig/Helpers/AppDbContext.cs @@ -43,6 +43,7 @@ namespace Elwig.Helpers { public DbSet DeliveryPartAttributes { get; private set; } public DbSet DeliveryPartModifiers { get; private set; } public DbSet PaymentVariants { get; private set; } + public DbSet MemberPayments { get; private set; } private readonly StreamWriter? LogFile = null; public static DateTime LastWriteTime => File.GetLastWriteTime(App.Config.DatabaseFile); diff --git a/Elwig/Models/Delivery.cs b/Elwig/Models/Delivery.cs index 4886d67..e548137 100644 --- a/Elwig/Models/Delivery.cs +++ b/Elwig/Models/Delivery.cs @@ -19,12 +19,8 @@ namespace Elwig.Models { [NotMapped] public DateOnly Date { - get { - return DateOnly.ParseExact(DateString, "yyyy-MM-dd"); - } - set { - DateString = value.ToString("yyyy-MM-dd"); - } + get => DateOnly.ParseExact(DateString, "yyyy-MM-dd"); + set => DateString = value.ToString("yyyy-MM-dd"); } [Column("time")] @@ -32,19 +28,13 @@ namespace Elwig.Models { [NotMapped] public TimeOnly? Time { - get { - return (TimeString == null) ? null : TimeOnly.ParseExact(TimeString, "HH:mm:ss"); - } - set { - TimeString = value?.ToString("HH:mm:ss"); - } + get => (TimeString == null) ? null : TimeOnly.ParseExact(TimeString, "HH:mm:ss"); + set => TimeString = value?.ToString("HH:mm:ss"); } [NotMapped] public DateTime DateTime { - get { - return Date.ToDateTime(Time ?? TimeOnly.MinValue); - } + get => Date.ToDateTime(Time ?? TimeOnly.MinValue); set { Date = DateOnly.FromDateTime(value); Time = TimeOnly.FromDateTime(value); @@ -72,6 +62,9 @@ namespace Elwig.Models { [Column("comment")] public string? Comment { get; set; } + [ForeignKey("Year")] + public virtual Season Season { get; private set; } + [InverseProperty("Delivery")] public virtual ISet Parts { get; private set; } diff --git a/Elwig/Models/PaymentMember.cs b/Elwig/Models/PaymentMember.cs new file mode 100644 index 0000000..56f1f43 --- /dev/null +++ b/Elwig/Models/PaymentMember.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Elwig.Models { + [Table("payment_member"), PrimaryKey("Year", "AvNr", "MgNr")] + public class PaymentMember { + [Column("year")] + public int Year { get; set; } + + [Column("avnr")] + public int AvNr { get; set; } + + [Column("mgnr")] + public int MgNr { get; set; } + + [Column("amount")] + public long AmountValue { get; set; } + + [NotMapped] + public decimal Amount { + get => Variant.Season.DecFromDb(AmountValue); + set => AmountValue = Variant.Season.DecToDb(value); + } + + [ForeignKey("Year, AvNr")] + public virtual PaymentVar Variant { get; private set; } + + [ForeignKey("MgNr")] + public virtual Member Member { get; private set; } + } +} diff --git a/Elwig/Models/PaymentVar.cs b/Elwig/Models/PaymentVar.cs index 689b6ca..573fb92 100644 --- a/Elwig/Models/PaymentVar.cs +++ b/Elwig/Models/PaymentVar.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using System; using System.ComponentModel.DataAnnotations.Schema; @@ -65,5 +65,8 @@ namespace Elwig.Models { [Column("data")] public string Data { get; set; } + + [ForeignKey("Year")] + public virtual Season Season { get; private set; } } } diff --git a/Elwig/Models/WineVar.cs b/Elwig/Models/WineVar.cs index 7f1ebc9..fe34151 100644 --- a/Elwig/Models/WineVar.cs +++ b/Elwig/Models/WineVar.cs @@ -18,6 +18,9 @@ namespace Elwig.Models { public string CommentFormat => (Comment != null) ? $" ({Comment})" : ""; + public bool IsRed => Type == "R"; + public bool IsWhite => Type == "W"; + public override string ToString() { return Name; }