public BondCalculatorViewModel() { //create model object calculatorModel = new BondCalculatorModel(); //create calculation engine object using Unity container //we can register other types for this interface in unity and use here e.g. FincadCalculationEngine, BrentEngine calculationEngine = UnityFactory.Resolve<IBondCalculationEngine>("Default"); //register event from model, will be raised when error state of model properties will change //will be used to enable/disable calculator button/radio button calculatorModel.NotifyVM = () => { NotifyPropertyChanged("ReadyForCalculation"); }; //command that binds to Calculate button. CalculateCommand = new DelegateCommand(param => PriceBond(), (param) => ((ReadyForCalculation) && (!calculationRunning))); //capture action when user wants to switch from ComputeYield to ComputePV and vice-versa YieldToggleCommand = new DelegateCommand(param => { yieldGiven = (bool)param; StatusText = ""; if (yieldGiven) { calculatorModel.Yield = 0.0m; calculatorModel.PresentValue = 0.0m; } }, (param) => true); PVToggleCommand = new DelegateCommand(param => { yieldGiven = !(bool)param; StatusText = ""; if (!yieldGiven) { calculatorModel.PresentValue = 0.0m; calculatorModel.Yield = 0.0m; } }, (param) => true); }
public void Init() { target = UnityFactory.Resolve<IBondCalculationEngine>("Default"); yieldPrecision = BondCalculator.Common.AppConfig.Instance.YieldPrecision; presentValuePrecision = BondCalculator.Common.AppConfig.Instance.PresentValuePrecision; }