Пример #1
0
        public InterestPlanViewModel(InterestPlanViewModelOption options)
        {
            Options  = options ?? throw new ArgumentNullException(nameof(options));
            Payments = new ObservableCollection <PaymentViewModel>();

            CalculateCommand = new DelegateCommand(() =>
            {
                if (!_isPlanUpdating)
                {
                    _isPlanUpdating    = true;
                    var newCalculation = Calculate(Payments);
                    foreach (var oldItem in Payments)
                    {
                        oldItem.PropertyChanged -= PaymentViewModel_PropertyChanged;
                    }
                    Payments.Clear();
                    foreach (var newCalculationItem in newCalculation)
                    {
                        Payments.Add(newCalculationItem);
                        newCalculationItem.PropertyChanged += PaymentViewModel_PropertyChanged;
                    }
                    RaisePropertyChanged(nameof(TotalInterest));
                    RaisePropertyChanged(nameof(ResidualDebt));
                    RaisePropertyChanged(nameof(RedemptionRate));
                    _isPlanUpdating = false;
                }
            });
            ResetCommand = new DelegateCommand(() => ResetAllInputValues());

            CalculateCommand.Execute();
        }
 public MainWindowViewModelDesignTime() : base(new ConfigurationBuilder().Build())
 {
     InterestPlanViewModels.Clear();
     InterestPlanViewModels.Add(new InterestPlanViewModel(InterestPlanViewModelOption.GetExample1()));
     InterestPlanViewModels.Add(new InterestPlanViewModel(InterestPlanViewModelOption.GetExample2()));
     Cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
 }
Пример #3
0
        public void InitializeKeepsProperties()
        {
            var plan = new InterestPlanViewModel(InterestPlanViewModelOption.GetExample1());

            var starMonth           = DateTime.Now;
            var loanAmount          = new Currency(100.0);
            var borrowingPercentage = new Percentage(0.001);
            var monthlyPayment      = new Currency(50.0);
            var years = 15;
            var unscheduledRepayment = new Percentage(.05);
            var redemptionPercentage = Calculator.GetRedemptionPercentage(loanAmount, borrowingPercentage, monthlyPayment);

            plan.StartMonth           = starMonth;
            plan.LoanAmount           = loanAmount;
            plan.Borrowing            = borrowingPercentage;
            plan.RedemptionRate       = redemptionPercentage;
            plan.Years                = years;
            plan.UnscheduledRepayment = unscheduledRepayment;

            // TODO: Do something or remove that
            var result = plan.Calculate(plan.Payments);

            Assert.Equal(years, plan.Years);
            Assert.Equal(starMonth, plan.StartMonth);
            Assert.Equal(borrowingPercentage, plan.Borrowing);
            Assert.Equal(monthlyPayment, Calculator.GetRedemptionAmount(loanAmount, borrowingPercentage, plan.RedemptionRate));
            Assert.Equal(loanAmount, plan.LoanAmount);
            Assert.Equal(unscheduledRepayment, plan.UnscheduledRepayment);
        }
Пример #4
0
        public void Properties()
        {
            var plan = new InterestPlanViewModel(InterestPlanViewModelOption.GetExample1());

            var starMonth            = DateTime.Now;
            var loan                 = new Currency(100.0);
            var borrowing            = new Percentage(0.001);
            var monthlyPayment       = new Currency(50.0);
            var years                = 15;
            var unscheduledRepayment = new Percentage(.05);
            var redemptionPercentage = Calculator.GetRedemptionPercentage(loan, borrowing, monthlyPayment);

            plan.StartMonth           = starMonth;
            plan.LoanAmount           = loan;
            plan.Borrowing            = borrowing;
            plan.RedemptionRate       = redemptionPercentage;
            plan.Years                = years;
            plan.UnscheduledRepayment = unscheduledRepayment;

            Assert.Equal(years, plan.Years);
            Assert.Equal(starMonth, plan.StartMonth);
            Assert.Equal(borrowing, plan.Borrowing);
            Assert.Equal(monthlyPayment, Calculator.GetRedemptionAmount(loan, borrowing, plan.RedemptionRate));
            Assert.Equal(loan, plan.LoanAmount);
            Assert.Equal(unscheduledRepayment, plan.UnscheduledRepayment);
        }
Пример #5
0
 private static void InitiateOptions(Rootobject options)
 {
     if (options.InterestPlanViewModelOptions.Count == 0)
     {
         options.InterestPlanViewModelOptions.Add(InterestPlanViewModelOption.GetExample1());
     }
     if (options.CultureInfo == null)
     {
         options.CultureInfo = Thread.CurrentThread.CurrentUICulture.ToString();
     }
 }
Пример #6
0
        public MainWindowViewModel(IConfiguration configuration)
        {
            InterestPlanViewModels = new ObservableCollection <InterestPlanViewModel>();
            InterestPlanViewModels.CollectionChanged += InterestPlanViewModels_CollectionChanged;

            var options = configuration.Get <Rootobject>() ?? new Rootobject();

            InitiateOptions(options);
            options.InterestPlanViewModelOptions.ForEach(ip => AddInterestPlanViewModel(new InterestPlanViewModel(ip)));

            SelectedCulture = CultureInfo.GetCultureInfo(options.CultureInfo);
            Cultures        = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

            CreateWindowCommand = new DelegateCommand(() => CreateWindow?.Invoke());

            AddInterestPlanCommand = new DelegateCommand(() =>
            {
                var p = new InterestPlanViewModel(InterestPlanViewModelOption.GetExample1());
                AddInterestPlanViewModel(p);
                SelectedInterestPlanViewModelIndex = InterestPlanViewModels.IndexOf(p);
            });

            DeleteInterestPlanCommand = new DelegateCommand(
                () =>
            {
                var interestPlanViewModel              = InterestPlanViewModels.ElementAt(SelectedInterestPlanViewModelIndex);
                interestPlanViewModel.PropertyChanged -= InterestPlanViewModel_PropertyChanged;
                InterestPlanViewModels.Remove(interestPlanViewModel);
            },
                () => InterestPlanViewModels.Count > 1
                );

            ResetAllCommand = new DelegateCommand(() => InterestPlanViewModels.ToList().ForEach(ip => ip.ResetCommand.Execute()));

            CalculateAllCommand = new DelegateCommand(() => InterestPlanViewModels.ToList().ForEach(ip => ip.CalculateCommand.Execute()));

            ResetAllCommand.Execute();
        }
Пример #7
0
 public InterestPlanViewModelDesignTime() : base(InterestPlanViewModelOption.GetExample1())
 {
 }