[#11] Tests: Add MemberServiceTest
This commit is contained in:
@ -25,7 +25,7 @@ namespace Elwig.Services {
|
||||
|
||||
public static async Task InitInputs(this MemberAdminViewModel vm) {
|
||||
using var ctx = new AppDbContext();
|
||||
vm.MgNrString = $"{await ctx.NextMgNr()}";
|
||||
vm.MgNr = await ctx.NextMgNr();
|
||||
vm.EntryDate = DateTime.Now.ToString("dd.MM.yyyy");
|
||||
if (vm.BranchSource.Count() == 1)
|
||||
vm.Branch = vm.BranchSource.First();
|
||||
@ -53,8 +53,8 @@ namespace Elwig.Services {
|
||||
|
||||
public static void FillInputs(this MemberAdminViewModel vm, Member m) {
|
||||
vm.IsMemberSelected = true;
|
||||
vm.MgNrString = $"{m.MgNr}";
|
||||
vm.PredecessorMgNrString = $"{m.PredecessorMgNr}";
|
||||
vm.MgNr = m.MgNr;
|
||||
vm.PredecessorMgNr = m.PredecessorMgNr;
|
||||
vm.IsJuridicalPerson = m.IsJuridicalPerson;
|
||||
vm.EnableMemberReferenceButton = m.PredecessorMgNr != null;
|
||||
vm.Prefix = m.Prefix;
|
||||
@ -73,10 +73,10 @@ namespace Elwig.Services {
|
||||
vm.IsDeceased = m.IsDeceased;
|
||||
vm.Address = m.Address;
|
||||
if (m.PostalDest.AtPlz is AT_PlzDest p) {
|
||||
vm.PlzString = $"{p.Plz}";
|
||||
vm.Plz = p.Plz;
|
||||
vm.Ort = ControlUtils.GetItemFromSource(vm.OrtSource, p);
|
||||
} else {
|
||||
vm.PlzString = null;
|
||||
vm.Plz = null;
|
||||
vm.Ort = null;
|
||||
}
|
||||
|
||||
@ -114,19 +114,19 @@ namespace Elwig.Services {
|
||||
vm.BillingName = billingAddr.FullName;
|
||||
vm.BillingAddress = billingAddr.Address;
|
||||
if (billingAddr.PostalDest.AtPlz is AT_PlzDest b) {
|
||||
vm.BillingPlzString = $"{b.Plz}";
|
||||
vm.BillingPlz = b.Plz;
|
||||
vm.BillingOrt = ControlUtils.GetItemFromSource(vm.BillingOrtSource, b);
|
||||
}
|
||||
} else {
|
||||
vm.BillingName = null;
|
||||
vm.BillingAddress = null;
|
||||
vm.BillingPlzString = null;
|
||||
vm.BillingPlz = null;
|
||||
vm.BillingOrt = null;
|
||||
}
|
||||
|
||||
vm.EntryDate = (m.EntryDateString != null) ? string.Join(".", m.EntryDateString.Split("-").Reverse()) : null;
|
||||
vm.ExitDate = (m.ExitDateString != null) ? string.Join(".", m.ExitDateString.Split("-").Reverse()) : null;
|
||||
vm.BusinessSharesString = $"{m.BusinessShares}";
|
||||
vm.BusinessShares = m.BusinessShares;
|
||||
vm.AccountingNr = m.AccountingNr;
|
||||
vm.Branch = (Branch?)ControlUtils.GetItemFromSourceWithPk(vm.BranchSource, m.ZwstId);
|
||||
vm.DefaultKg = (AT_Kg?)ControlUtils.GetItemFromSourceWithPk(vm.DefaultKgSource, m.DefaultKgNr);
|
||||
@ -148,6 +148,8 @@ namespace Elwig.Services {
|
||||
vm.StatusAreaCommitmentToolTip = null;
|
||||
|
||||
Utils.RunBackground("Mitgliederdaten laden", async () => {
|
||||
if (App.MainDispatcher == null)
|
||||
return;
|
||||
using var ctx = new AppDbContext();
|
||||
|
||||
var d1 = ctx.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason - 1 && d.MgNr == m.MgNr);
|
||||
@ -652,5 +654,23 @@ namespace Elwig.Services {
|
||||
|
||||
return newMgNr;
|
||||
}
|
||||
|
||||
public static async Task DeleteMember(int mgnr, bool deletePaymentData, bool deleteDeliveries, bool deleteAreaComs) {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
var l = (await ctx.Members.FindAsync(mgnr))!;
|
||||
if (deletePaymentData) {
|
||||
ctx.RemoveRange(l.Credits);
|
||||
}
|
||||
if (deleteDeliveries) {
|
||||
ctx.RemoveRange(l.Deliveries);
|
||||
}
|
||||
if (deleteAreaComs) {
|
||||
ctx.RemoveRange(l.AreaCommitments);
|
||||
}
|
||||
ctx.Remove(l);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
App.HintContextChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user