Dtos: Add more DTOs

This commit is contained in:
2023-11-15 16:40:17 +01:00
parent d485f0fda1
commit 486655d071
8 changed files with 372 additions and 140 deletions

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Elwig.Models.Dtos {
public class DeliveryConfirmationData : DataTable<DeliveryConfirmationRow> {
private static readonly (string, string)[] _fieldNames = new[] {
private static readonly (string, string)[] FieldNames = new[] {
("LsNr", "LsNr."),
("DPNr", "Pos."),
("Variant", "Sorte"),
@ -20,24 +20,24 @@ namespace Elwig.Models.Dtos {
("Weight", "Gewicht"),
};
public int MgNr { get; private set; }
private readonly int MgNr;
private DeliveryConfirmationData(IEnumerable<DeliveryConfirmationRow> rows, int mgnr) :
base("Anl.-Best.", "Anlieferungsbestätigung", rows, _fieldNames) {
MgNr = mgnr;
private DeliveryConfirmationData(IEnumerable<DeliveryConfirmationRow> rows, int year, Member m) :
base($"Anlieferungsbestätigung", $"Anlieferungsbestätigung {year} {m.AdministrativeName}", rows, FieldNames) {
MgNr = m.MgNr;
}
public static async Task<IDictionary<int, DeliveryConfirmationData>> ForSeason(DbSet<DeliveryPart> table, int year) {
return (await FromDbSet(table, year))
.GroupBy(
p => p.Delivery.MgNr,
p => p.Delivery.Member,
p => new DeliveryConfirmationRow(p),
(k, g) => new DeliveryConfirmationData(g, k)
(k, g) => new DeliveryConfirmationData(g, year, k)
).ToDictionary(d => d.MgNr, d => d);
}
public static async Task<DeliveryConfirmationData> ForMember(DbSet<DeliveryPart> table, int year, int mgnr) {
return new DeliveryConfirmationData((await FromDbSet(table, year, mgnr)).Select(p => new DeliveryConfirmationRow(p)), mgnr);
public static async Task<DeliveryConfirmationData> ForMember(DbSet<DeliveryPart> table, int year, Member m) {
return new DeliveryConfirmationData((await FromDbSet(table, year, m.MgNr)).Select(p => new DeliveryConfirmationRow(p)), year, m);
}
private static async Task<IEnumerable<DeliveryPart>> FromDbSet(DbSet<DeliveryPart> table, int? year = null, int? mgnr = null) {
@ -66,7 +66,6 @@ namespace Elwig.Models.Dtos {
}
public class DeliveryConfirmationRow {
public string LsNr;
public int DPNr;
public string Variant;