MemberList: Allow filtering area commitments
This commit is contained in:
@ -31,6 +31,7 @@ namespace Elwig.Models.Dtos {
|
||||
("EntryDate", "Eintritt", null, 20),
|
||||
("ExitDate", "Austritt", null, 20),
|
||||
("AreaCommitment", "geb. Fläche", "m²", 20),
|
||||
("AreaCommitmentsFiltered", "geb. Fläche", "Vtrg.|m²", 30),
|
||||
("UstIdNr", "UID", null, 25),
|
||||
("Iban", "IBAN", null, 45),
|
||||
("Bic", "BIC", null, 30),
|
||||
@ -45,8 +46,8 @@ namespace Elwig.Models.Dtos {
|
||||
base(MemberList.Name, MemberList.Name, string.Join(" / ", filterNames), rows, FieldNames) {
|
||||
}
|
||||
|
||||
public static async Task<MemberListData> FromQuery(IQueryable<Member> query, List<string> filterNames) {
|
||||
var areaCom = await query.ToDictionaryAsync(m => m.MgNr, m => Utils.ActiveAreaCommitments(m.AreaCommitments).Sum(c => c.Area));
|
||||
public static async Task<MemberListData> FromQuery(IQueryable<Member> query, List<string> filterNames, IEnumerable<string> filterAreaCom) {
|
||||
var areaComs = await query.ToDictionaryAsync(m => m.MgNr, m => Utils.ActiveAreaCommitments(m.AreaCommitments));
|
||||
return new((await query
|
||||
.Include(m => m.DefaultWbKg!.AtKg)
|
||||
.Include(m => m.Branch)
|
||||
@ -55,13 +56,17 @@ namespace Elwig.Models.Dtos {
|
||||
.Include(m => m.TelephoneNumbers)
|
||||
.Include(m => m.EmailAddresses)
|
||||
.AsSplitQuery()
|
||||
.ToListAsync()).Select(m => new MemberListRow(m, areaCom[m.MgNr])), filterNames);
|
||||
.ToListAsync()).Select(m => new MemberListRow(m,
|
||||
areaComs[m.MgNr].Sum(c => c.Area),
|
||||
areaComs[m.MgNr].Where(c => filterAreaCom.Contains(c.VtrgId)).GroupBy(c => c.VtrgId).ToDictionary(g => g.Key, g => g.Sum(c => c.Area)))),
|
||||
filterNames);
|
||||
}
|
||||
}
|
||||
|
||||
public class MemberListRow {
|
||||
public int MgNr;
|
||||
public string? Name1;
|
||||
public string? AdminName1;
|
||||
public string? Name2;
|
||||
public string? DefaultKg;
|
||||
public string? Branch;
|
||||
@ -78,6 +83,7 @@ namespace Elwig.Models.Dtos {
|
||||
public string? Iban;
|
||||
public string? Bic;
|
||||
public int? AreaCommitment;
|
||||
public (string VtrgId, int Area)[] AreaCommitmentsFiltered;
|
||||
public bool IsBuchführend;
|
||||
public bool IsOrganic;
|
||||
public bool IsActive;
|
||||
@ -89,9 +95,10 @@ namespace Elwig.Models.Dtos {
|
||||
public string? AdditionalContact;
|
||||
public string? Comment;
|
||||
|
||||
public MemberListRow(Member m, int? areaCom = null) {
|
||||
public MemberListRow(Member m, int? areaCom = null, Dictionary<string, int>? filtered = null) {
|
||||
MgNr = m.MgNr;
|
||||
Name1 = m.Name;
|
||||
AdminName1 = m.AdministrativeName1;
|
||||
Name2 = m.AdministrativeName2;
|
||||
DefaultKg = m.DefaultKg?.Name;
|
||||
Branch = m.Branch?.Name;
|
||||
@ -125,6 +132,7 @@ namespace Elwig.Models.Dtos {
|
||||
.Concat(m.EmailAddresses.OrderBy(a => a.Nr).Select(a => a.Address).Except([EmailAddress])));
|
||||
Comment = m.Comment;
|
||||
AreaCommitment = areaCom == 0 ? null : areaCom;
|
||||
AreaCommitmentsFiltered = filtered != null ? filtered.OrderBy(f => f.Key).Select(f => (f.Key, f.Value)).ToArray() : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user