[#11] Tests: Add MemberServiceTest
This commit is contained in:
@ -205,6 +205,7 @@ namespace Elwig {
|
||||
}
|
||||
|
||||
public static void HintContextChange() {
|
||||
if (CurrentApp == null) return;
|
||||
var ch = CurrentLastWrite;
|
||||
if (ch > CurrentApp.LastChanged)
|
||||
CurrentApp.LastChanged = ch;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace Elwig.ViewModels {
|
||||
[ObservableProperty]
|
||||
private bool _enableSearchInputs = true;
|
||||
[ObservableProperty]
|
||||
private IEnumerable<bool> _memberHasDeliveries = [ .. Enumerable.Range(0, 9999).Select(i => false) ];
|
||||
private IEnumerable<bool> _memberHasDeliveries = [.. Enumerable.Range(0, 9999).Select(i => false)];
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _memberListOrderByMgNr;
|
||||
@ -50,10 +50,16 @@ namespace Elwig.ViewModels {
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _mgNrString;
|
||||
public int? MgNr => int.TryParse(MgNrString, out var mgnr) ? mgnr : null;
|
||||
public int? MgNr {
|
||||
get => int.TryParse(MgNrString, out var mgnr) ? mgnr : null;
|
||||
set => MgNrString = $"{value}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string? _predecessorMgNrString;
|
||||
public int? PredecessorMgNr => int.TryParse(PredecessorMgNrString, out var mgnr) ? mgnr : null;
|
||||
public int? PredecessorMgNr {
|
||||
get => int.TryParse(PredecessorMgNrString, out var mgnr) ? mgnr : null;
|
||||
set => PredecessorMgNrString = $"{value}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private bool _isJuridicalPerson;
|
||||
[ObservableProperty]
|
||||
@ -76,7 +82,10 @@ namespace Elwig.ViewModels {
|
||||
private string? _address;
|
||||
[ObservableProperty]
|
||||
private string? _plzString;
|
||||
public int? Plz => int.TryParse(PlzString, out var plz) ? plz : null;
|
||||
public int? Plz {
|
||||
get => int.TryParse(PlzString, out var plz) ? plz : null;
|
||||
set => PlzString = $"{value}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private AT_PlzDest? _ort;
|
||||
[ObservableProperty]
|
||||
@ -88,7 +97,10 @@ namespace Elwig.ViewModels {
|
||||
private string? _billingAddress;
|
||||
[ObservableProperty]
|
||||
private string? _billingPlzString;
|
||||
public int? BillingPlz => int.TryParse(BillingPlzString, out var plz) ? plz : null;
|
||||
public int? BillingPlz {
|
||||
get => int.TryParse(BillingPlzString, out var plz) ? plz : null;
|
||||
set => BillingPlzString = $"{value}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private AT_PlzDest? _billingOrt;
|
||||
[ObservableProperty]
|
||||
@ -114,7 +126,10 @@ namespace Elwig.ViewModels {
|
||||
private string? _exitDate;
|
||||
[ObservableProperty]
|
||||
private string? _businessSharesString;
|
||||
public int? BusinessShares => int.TryParse(BusinessSharesString, out var bs) ? bs : null;
|
||||
public int? BusinessShares {
|
||||
get => int.TryParse(BusinessSharesString, out var bs) ? bs : null;
|
||||
set => BusinessSharesString = $"{value}";
|
||||
}
|
||||
[ObservableProperty]
|
||||
private string? _accountingNr;
|
||||
[ObservableProperty]
|
||||
@ -147,6 +162,14 @@ namespace Elwig.ViewModels {
|
||||
public string? _number = number;
|
||||
[ObservableProperty]
|
||||
public string? _comment = comment;
|
||||
|
||||
public override bool Equals(object? obj) {
|
||||
return obj is PhoneNr nr && Type == nr.Type && Number == nr.Number && Comment == nr.Comment;
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return Type ^ (Number?.GetHashCode() ?? 0) ^ (Comment?.GetHashCode() ?? 0);
|
||||
}
|
||||
}
|
||||
public ObservableCollection<PhoneNr> PhoneNrs { get; private set; } = [new(), new(), new(), new(), new(), new(), new(), new(), new()];
|
||||
|
||||
|
@ -360,21 +360,7 @@ namespace Elwig.Windows {
|
||||
if (d.ShowDialog() == true) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
var l = (await ctx.Members.FindAsync(m.MgNr))!;
|
||||
if (d.DeletePaymentData) {
|
||||
ctx.RemoveRange(l.Credits);
|
||||
}
|
||||
if (d.DeleteDeliveries) {
|
||||
ctx.RemoveRange(l.Deliveries);
|
||||
}
|
||||
if (d.DeleteAreaComs) {
|
||||
ctx.RemoveRange(l.AreaCommitments);
|
||||
}
|
||||
ctx.Remove(l);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
App.HintContextChange();
|
||||
await MemberService.DeleteMember(m.MgNr, d.DeletePaymentData, d.DeleteDeliveries, d.DeleteAreaComs);
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
|
Reference in New Issue
Block a user