diff --git a/BookAStar/BookAStar/Pages/BookQueryPage.xaml b/BookAStar/BookAStar/Pages/BookQueryPage.xaml
index d8c19a23..11b3d615 100644
--- a/BookAStar/BookAStar/Pages/BookQueryPage.xaml
+++ b/BookAStar/BookAStar/Pages/BookQueryPage.xaml
@@ -26,9 +26,8 @@
-
-
-
+
+
\ No newline at end of file
diff --git a/BookAStar/BookAStar/Pages/BookQueryPage.xaml.cs b/BookAStar/BookAStar/Pages/BookQueryPage.xaml.cs
index f547338c..57173a3c 100644
--- a/BookAStar/BookAStar/Pages/BookQueryPage.xaml.cs
+++ b/BookAStar/BookAStar/Pages/BookQueryPage.xaml.cs
@@ -7,6 +7,7 @@ namespace BookAStar.Pages
using Data;
using Model;
using Model.Workflow;
+ using System.Linq;
using ViewModels;
public partial class BookQueryPage : ContentPage
@@ -57,23 +58,35 @@ namespace BookAStar.Pages
private void OnEditEstimate(object sender, EventArgs ev)
{
- var viewModel = ((BookQueryViewModel)BindingContext).DraftEstimate;
- if (viewModel == null)
+ var bookQueryViewModel = (BookQueryViewModel)BindingContext;
+
+ var editEstimateViewModel = bookQueryViewModel.DraftEstimate;
+ if (editEstimateViewModel == null)
{
- DataManager.Current.Contacts.Merge(BookQuery.Client);
- var e = new Estimate()
+ // First search for an existing estimate
+ var estimateToEdit = DataManager.Current.Estimates.FirstOrDefault(
+ estimate=> estimate.CommandId == bookQueryViewModel.Id
+ );
+ if (estimateToEdit == null)
{
- ClientId = BookQuery.Client.UserId,
- CommandId = BookQuery.Id,
- OwnerId = MainSettings.CurrentUser.Id,
- Id = 0,
- Description = "# **Hello Estimate!**"
- };
- viewModel = new EditEstimateViewModel(e, LocalState.New);
- DataManager.Current.EstimationCache.Add(viewModel);
+ DataManager.Current.Contacts.Merge(BookQuery.Client);
+ estimateToEdit = new Estimate()
+ {
+ ClientId = BookQuery.Client.UserId,
+ CommandId = BookQuery.Id,
+ OwnerId = MainSettings.CurrentUser.Id,
+ Id = 0,
+ Description = "# **Hello Estimate!**"
+ };
+ editEstimateViewModel = new EditEstimateViewModel(estimateToEdit, LocalState.New);
+ }
+ else
+ editEstimateViewModel = new EditEstimateViewModel(estimateToEdit, LocalState.UpToDate);
+
+ DataManager.Current.EstimationCache.Add(editEstimateViewModel);
}
App.NavigationService.NavigateTo(true,
- viewModel);
+ editEstimateViewModel);
}
protected override void OnSizeAllocated(double width, double height)
diff --git a/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml b/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml
index bd66e782..6ce717aa 100644
--- a/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml
+++ b/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml
@@ -93,8 +93,10 @@
Path=IsValid,
Converter={StaticResource boolToStyleImage}}" />
-
-
+
diff --git a/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml.cs b/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml.cs
index 863add5f..779d189e 100644
--- a/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml.cs
+++ b/BookAStar/BookAStar/Pages/EditBillingLinePage.xaml.cs
@@ -21,5 +21,11 @@ namespace BookAStar.Pages
{
this.Navigation.PopAsync();
}
+ protected override bool OnBackButtonPressed()
+ {
+ var bvm = (BillingLineViewModel)BindingContext;
+ bvm.ValidateCommand?.Execute(null);
+ return base.OnBackButtonPressed();
+ }
}
}
diff --git a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml
index a3c5be6e..3e4a4bc4 100644
--- a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml
+++ b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml
@@ -40,7 +40,7 @@
+ HeightRequest="40" ItemTapped="OnEditLine">
diff --git a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs
index 3bfdae2b..4c46a728 100644
--- a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs
+++ b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs
@@ -14,6 +14,7 @@ namespace BookAStar.Pages
InitializeComponent();
BindingContext = model;
}
+
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
@@ -41,17 +42,36 @@ namespace BookAStar.Pages
protected void OnNewCommanLine(object sender, EventArgs e)
{
var com = new BillingLine() { Count = 1, UnitaryCost = 0.01m };
- var lineView = new BillingLineViewModel(com);
- var bill =
- ((EditEstimateViewModel)BindingContext).Bill;
- bill.Add(com);
- bill.SaveCollection();
- lineView.PropertyChanged += (s,f) => bill.SaveCollection();
+ var bill = ((EditEstimateViewModel)BindingContext).Bill;
+ var lineView = new BillingLineViewModel(com)
+ { ValidateCommand = new Command(() => {
+ bill.Add(com);
+ bill.SaveCollection();
+ })};
App.NavigationService.NavigateTo(
true,
new object[] { lineView } );
}
+ protected void OnEditLine(object sender, ItemTappedEventArgs e)
+ {
+ var line = (BillingLine)e.Item;
+ var bill = ((EditEstimateViewModel)BindingContext).Bill;
+ var lineView = new BillingLineViewModel(line)
+ {
+ ValidateCommand = new Command(() => {
+ bill.SaveCollection();
+ })
+ };
+ lineView.PropertyChanged += LineView_PropertyChanged;
+ App.NavigationService.NavigateTo(
+ true,
+ new object[] { lineView });
+ }
+ private void LineView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ DataManager.Current.EstimationCache.SaveCollection();
+ }
protected void OnEstimateValidated(object sender, EventArgs e)
{
@@ -68,7 +88,9 @@ namespace BookAStar.Pages
DataManager.Current.Estimates.Update(evm.Data);
}
DataManager.Current.Estimates.SaveCollection();
- evm.State = LocalState.UpToDate;
+ DataManager.Current.EstimationCache.Remove(evm);
+ DataManager.Current.EstimationCache.SaveCollection();
+ Navigation.PopAsync();
}
}
}
diff --git a/BookAStar/BookAStar/ViewModels/BillingLineViewModel.cs b/BookAStar/BookAStar/ViewModels/BillingLineViewModel.cs
index 0ff1d92f..051280bb 100644
--- a/BookAStar/BookAStar/ViewModels/BillingLineViewModel.cs
+++ b/BookAStar/BookAStar/ViewModels/BillingLineViewModel.cs
@@ -13,48 +13,57 @@ namespace BookAStar.ViewModels
{
BillingLine data;
- public BillingLineViewModel( BillingLine data)
+ public BillingLineViewModel(BillingLine data)
{
this.data = data ?? new BillingLine();
// sets durationValue & durationUnit
+ count = data.Count;
+ description = data.Description;
+
Duration = data.Duration;
- unitaryCostText = data.UnitaryCost.ToString("G",CultureInfo.InvariantCulture);
+ unitaryCostText = data.UnitaryCost.ToString("G", CultureInfo.InvariantCulture);
}
+ private int count;
public int Count
{
get
{
- return data.Count;
+ return count;
}
set
{
- data.Count = value;
+ SetProperty(ref count, value);
+ data.Count = count;
}
}
+ private string description;
public string Description
{
get
{
- return data.Description;
+ return description;
}
set
{
- data.Description = value;
+ SetProperty(ref description, value);
+ data.Description = description;
}
}
+ decimal unitaryCost;
public decimal UnitaryCost
{
get
{
- return data.UnitaryCost;
+ return unitaryCost;
}
set
{
- data.UnitaryCost = value;
+ SetProperty(ref unitaryCost, value);
+ data.UnitaryCost = unitaryCost;
}
}
@@ -72,12 +81,12 @@ namespace BookAStar.ViewModels
data.Duration = this.Duration;
}
}
-
- public enum DurationUnits:int
+
+ public enum DurationUnits : int
{
- Jours=0,
- Heures=1,
- Minutes=2
+ Jours = 0,
+ Heures = 1,
+ Minutes = 2
}
private DurationUnits durationUnit;
@@ -85,17 +94,17 @@ namespace BookAStar.ViewModels
pour décrire la quantité de travail associée à ce type de service")]
public DurationUnits DurationUnit
{
- get {
+ get
+ {
return durationUnit;
}
set
{
- SetProperty(ref durationUnit, value, "DurationUnit");
- data.Duration = this.Duration;
+ SetProperty(ref durationUnit, value, "DurationUnit");
+ data.Duration = this.Duration;
}
}
-
- protected decimal unitaryCost;
+
public static readonly string unitCostFormat = "0,.00";
string unitaryCostText;
public string UnitaryCostText
@@ -129,7 +138,7 @@ pour décrire la quantité de travail associée à ce type de service")]
case DurationUnits.Heures:
return new TimeSpan(DurationValue, 0, 0);
case DurationUnits.Jours:
- return new TimeSpan(DurationValue*24, 0, 0);
+ return new TimeSpan(DurationValue * 24, 0, 0);
case DurationUnits.Minutes:
return new TimeSpan(0, DurationValue, 0);
// Assert(false); since all units are treated bellow
@@ -143,21 +152,21 @@ pour décrire la quantité de travail associée à ce type de service")]
double days = value.TotalDays;
if (days >= 1.0)
{
- DurationValue = (int) days;
+ DurationValue = (int)days;
DurationUnit = DurationUnits.Jours;
return;
}
double hours = value.TotalHours;
if (hours >= 1.0)
{
- DurationValue = (int) hours;
+ DurationValue = (int)hours;
DurationUnit = DurationUnits.Jours;
return;
}
- DurationValue = (int) value.TotalMinutes;
+ DurationValue = (int)value.TotalMinutes;
DurationUnit = DurationUnits.Minutes;
}
}
-
+
}
}