Created
November 6, 2015 09:29
-
-
Save GeertVL-zz/88c30a60084f632de2f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TipCalculatorViewModel : INotifyPropertyChanged | |
{ | |
private readonly TipCalculation _model; | |
private readonly ITipCalculatorRepository _repository; | |
public event PropertyChangedEventHandler PropertyChanged; | |
public TipCalculatorViewModel(ITipCalculatorRepository repository) | |
{ | |
_model = new TipCalculation(); | |
_repository = repository; | |
SaveCalculationCommand = new RelayCommand<TipCalculation>(SaveCalculation); | |
} | |
public decimal BillAmount | |
{ | |
get { return _model.BillAmount; } | |
set | |
{ | |
_model.BillAmount = value; | |
OnPropertyChanged(nameof(BillAmount)); | |
} | |
} | |
public decimal TipRate | |
{ | |
get { return _model.TipRate; } | |
set | |
{ | |
_model.TipRate = value; | |
OnPropertyChanged(nameof(TipRate)); | |
} | |
} | |
public decimal Tip => Math.Round(BillAmount * (TipRate / 100), 2); | |
public decimal Total => BillAmount + TipRate; | |
public ICommand SaveCalculationCommand { get; private set; } | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
private void SaveCalculation(TipCalculation model) | |
{ | |
model.Tip = Tip; | |
model.Total = Total; | |
//Save it | |
_repository.Save(model); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TipCalculatorViewModel : INotifyPropertyChanged | |
{ | |
private readonly TipCalculation _model; | |
private readonly ITipCalculatorRepository _repository; | |
public event PropertyChangedEventHandler PropertyChanged; | |
public TipCalculatorViewModel(TipCalculation model, ITipCalculatorRepository repository) | |
{ | |
_model = model; | |
_repository = repository; | |
SaveCalculationCommand = new RelayCommand<TipCalculation>(SaveCalculation); | |
} | |
public decimal BillAmount | |
{ | |
get { return _model.BillAmount; } | |
set | |
{ | |
_model.BillAmount = value; | |
OnPropertyChanged(nameof(BillAmount)); | |
} | |
} | |
public decimal TipRate | |
{ | |
get { return _model.TipRate; } | |
set | |
{ | |
_model.TipRate = value; | |
OnPropertyChanged(nameof(TipRate)); | |
} | |
} | |
public decimal Tip => Math.Round(BillAmount * (TipRate / 100), 2); | |
public decimal Total => BillAmount + TipRate; | |
public ICommand SaveCalculationCommand { get; private set; } | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
private void SaveCalculation(TipCalculation model) | |
{ | |
model.Tip = Tip; | |
model.Total = Total; | |
//Save it | |
_repository.Save(model); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment