48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using Elwig.Models.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Elwig.Helpers.Billing {
|
|
public class ContractSelection : IComparable<ContractSelection> {
|
|
|
|
public WineVar? Variety { get; }
|
|
public WineAttr? Attribute { get; }
|
|
public string Listing => Variety != null || Attribute != null ? $"{Variety?.SortId}{Attribute?.AttrId}" : "";
|
|
|
|
public ContractSelection(WineVar? var, WineAttr? attr) {
|
|
Variety = var;
|
|
Attribute = attr;
|
|
}
|
|
|
|
public ContractSelection(WineVar var) {
|
|
Variety = var;
|
|
}
|
|
|
|
public ContractSelection(WineAttr attr) {
|
|
Attribute = attr;
|
|
}
|
|
|
|
public override string ToString() {
|
|
return (Variety != null ? $"{Variety.Name}" : "") + (Attribute != null ? $" {Attribute.Name}" : "");
|
|
}
|
|
|
|
public static List<ContractSelection> GetContractsForYear(AppDbContext context, int year) {
|
|
return context.DeliveryParts
|
|
.Where(d => d.Year == year)
|
|
.Select(d => new ContractSelection(d.Variant, d.Attribute))
|
|
.Distinct()
|
|
.ToList()
|
|
.Union(context.WineVarieties.Select(v => new ContractSelection(v)))
|
|
.ToList();
|
|
}
|
|
|
|
public int CompareTo(ContractSelection? other) {
|
|
//MessageBox.Show($"{Listing} -- {other.Listing} : {Listing.CompareTo(other.Listing)}");
|
|
return other != null ?
|
|
Listing.CompareTo(other.Listing) :
|
|
throw new ArgumentException();
|
|
}
|
|
}
|
|
}
|