Implement option to update billing address
This commit is contained in:
@ -279,8 +279,6 @@ namespace Elwig.Windows {
|
||||
m.LfbisNr = (LfbisNrInput.Text == "") ? null : LfbisNrInput.Text;
|
||||
m.IsBuchführend = BuchführendInput.IsChecked ?? false;
|
||||
|
||||
// TODO Rechnungsadresse
|
||||
|
||||
m.EntryDateString = (EntryDateInput.Text == "") ? null : string.Join("-", EntryDateInput.Text.Split(".").Reverse());
|
||||
m.ExitDateString = (ExitDateInput.Text == "") ? null : string.Join("-", ExitDateInput.Text.Split(".").Reverse());
|
||||
m.BusinessShares = (BusinessSharesInput.Text == "") ? 0 : int.Parse(BusinessSharesInput.Text);
|
||||
@ -303,6 +301,26 @@ namespace Elwig.Windows {
|
||||
m.MgNr = newMgNr;
|
||||
tr = (await Context.AddAsync(m));
|
||||
}
|
||||
|
||||
if (BillingOrtInput.SelectedItem == null) {
|
||||
if (m.BillingAddress != null) {
|
||||
Context.Remove(m.BillingAddress);
|
||||
}
|
||||
} else {
|
||||
BillingAddr b = m.BillingAddress ?? Context.CreateProxy<BillingAddr>();
|
||||
b.Name = BillingNameInput.Text;
|
||||
b.Address = BillingAddressInput.Text;
|
||||
var p = (AT_PlzDest)BillingOrtInput.SelectedItem;
|
||||
b.CountryCode = p.CountryCode;
|
||||
b.PostalDestId = p.Id;
|
||||
if (m.BillingAddress == null) {
|
||||
b.MgNr = newMgNr;
|
||||
await Context.AddAsync(b);
|
||||
} else {
|
||||
Context.Update(b);
|
||||
}
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
if (newMgNr != m.MgNr) {
|
||||
@ -356,7 +374,7 @@ namespace Elwig.Windows {
|
||||
|
||||
var billingAddr = m.BillingAddress;
|
||||
if (billingAddr != null) {
|
||||
BillingName.Text = billingAddr.Name;
|
||||
BillingNameInput.Text = billingAddr.Name;
|
||||
BillingAddressInput.Text = billingAddr.Address;
|
||||
AT_PlzDest? b = billingAddr.PostalDest.AtPlz;
|
||||
if (b != null) {
|
||||
@ -365,7 +383,7 @@ namespace Elwig.Windows {
|
||||
BillingOrtInput.SelectedItem = b;
|
||||
}
|
||||
} else {
|
||||
BillingName.Text = "";
|
||||
BillingNameInput.Text = "";
|
||||
BillingAddressInput.Text = "";
|
||||
BillingPlzInput.Text = "";
|
||||
BillingOrtInput.ItemsSource = null;
|
||||
@ -402,7 +420,7 @@ namespace Elwig.Windows {
|
||||
|
||||
override protected void UpdateButtons() {
|
||||
if (!IsEditing && !IsCreating) return;
|
||||
bool ch = HasChanged(), v = IsValid();
|
||||
bool ch = HasChanged, v = IsValid;
|
||||
ResetButton.IsEnabled = (ch);
|
||||
SaveButton.IsEnabled = (v && ch);
|
||||
}
|
||||
|
Reference in New Issue
Block a user