should make persist any estimate line edition

This commit is contained in:
Paul Schneider 2016-10-20 01:35:35 +02:00
commit c9329a8c03

View file

@ -41,31 +41,34 @@ namespace BookAStar.Pages
protected void OnNewCommanLine(object sender, EventArgs e) protected void OnNewCommanLine(object sender, EventArgs e)
{ {
var com = new BillingLine() { Count = 1, UnitaryCost = 0.01m }; var com = new BillingLine() { Count = 1, UnitaryCost = 0.01m };
var lineView = new BillingLineViewModel(com) var lineView = new BillingLineViewModel(com);
{ var bill =
ValidateCommand = new Command(() => { ((EditEstimateViewModel)BindingContext).Bill;
((EditEstimateViewModel)BindingContext).Bill. bill.Add(com);
Add(com); bill.SaveCollection();
}) lineView.PropertyChanged += (s,f) => bill.SaveCollection();
};
App.NavigationService.NavigateTo<EditBillingLinePage>( App.NavigationService.NavigateTo<EditBillingLinePage>(
true, true,
new object[] { lineView } ); new object[] { lineView } );
} }
protected void OnEstimateValidated(object sender, EventArgs e) protected void OnEstimateValidated(object sender, EventArgs e)
{ {
var evm = (EditEstimateViewModel)BindingContext; var evm = (EditEstimateViewModel)BindingContext;
if (evm.State == LocalState.New) if (evm.Data.Id == 0)
{ {
DataManager.Current.Estimates.Create(evm.Data); DataManager.Current.Estimates.Create(evm.Data);
// we have to manually add this item in our local collection, // we have to manually add this item in our local collection,
// since we could prefer to update the whole collection // since we could prefer to update the whole collection
// from server, or whatever other scenario // from server, or whatever other scenario
DataManager.Current.Estimates.Add(evm.Data); DataManager.Current.Estimates.Add(evm.Data);
evm.State = LocalState.UpToDate; } else
{
DataManager.Current.Estimates.Update(evm.Data);
} }
DataManager.Current.Estimates.SaveCollection();
evm.State = LocalState.UpToDate;
} }
} }
} }