From 7dec77ca46b452fe702ea69ecb8c28b43184a27b Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 20 Oct 2016 01:35:35 +0200 Subject: [PATCH] should make persist any estimate line edition --- .../BookAStar/Pages/EditEstimatePage.xaml.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs index a1227f77..3bfdae2b 100644 --- a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs @@ -41,31 +41,34 @@ namespace BookAStar.Pages protected void OnNewCommanLine(object sender, EventArgs e) { var com = new BillingLine() { Count = 1, UnitaryCost = 0.01m }; - var lineView = new BillingLineViewModel(com) - { - ValidateCommand = new Command(() => { - ((EditEstimateViewModel)BindingContext).Bill. - Add(com); - }) - }; - + var lineView = new BillingLineViewModel(com); + var bill = + ((EditEstimateViewModel)BindingContext).Bill; + bill.Add(com); + bill.SaveCollection(); + lineView.PropertyChanged += (s,f) => bill.SaveCollection(); App.NavigationService.NavigateTo( true, new object[] { lineView } ); } + protected void OnEstimateValidated(object sender, EventArgs e) { var evm = (EditEstimateViewModel)BindingContext; - if (evm.State == LocalState.New) + if (evm.Data.Id == 0) { DataManager.Current.Estimates.Create(evm.Data); // we have to manually add this item in our local collection, // since we could prefer to update the whole collection // from server, or whatever other scenario 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; } } }