public async Task <SimulateGoalResultVM> AddAsync(SimulateGoalVM simulateGoalVM)
        {
            var request = await _mediator.Send(new CreateRequest <SimulateGoalVM>(simulateGoalVM));

            var result = Simulate(request);

            return(result);
        }
        private SimulateGoalResultVM Simulate(SimulateGoalVM simulateGoalVM)
        {
            SimulateGoalResultVM simulateGoalResultVM = new SimulateGoalResultVM();

            simulateGoalResultVM.Goals          = new List <GoalResult>();
            simulateGoalResultVM.AnnualPercente = simulateGoalVM.AnnualPercente;
            simulateGoalResultVM.BeginValue     = simulateGoalVM.BeginValue;
            foreach (var contribution in simulateGoalVM.Contributions)
            {
                GoalResult goalResult = new GoalResult();

                var percentage = 0.0;
                switch (simulateGoalVM.DateKind)
                {
                case DateKindEnum.Year:
                    goalResult.Date = contribution.Date;
                    percentage      = simulateGoalVM.AnnualPercente;
                    break;

                case DateKindEnum.Month:
                    goalResult.Date = contribution.Date;
                    percentage      = simulateGoalVM.AnnualPercente / 12;
                    break;

                case DateKindEnum.Week:
                    goalResult.Date = contribution.Date;
                    percentage      = simulateGoalVM.AnnualPercente / 52;
                    break;

                case DateKindEnum.WorkDay:
                    throw new NotImplementedException();

                default:
                    goalResult.Date = contribution.Date;
                    percentage      = simulateGoalVM.AnnualPercente;
                    break;
                }

                if (simulateGoalResultVM.Goals.Any())
                {
                    goalResult.CurrentValue = simulateGoalResultVM.Goals.LastOrDefault().Goal;
                }
                else
                {
                    goalResult.CurrentValue = simulateGoalVM.BeginValue;
                }

                goalResult.Contribution = contribution.Value;
                var finalValue      = goalResult.Contribution + goalResult.CurrentValue;
                var percentageValue = finalValue * ((decimal)percentage / 100);
                goalResult.Goal = finalValue + percentageValue;

                simulateGoalResultVM.Goals.Add(goalResult);
            }
            simulateGoalResultVM.FinalGoal = simulateGoalResultVM.Goals.LastOrDefault();
            return(simulateGoalResultVM);
        }
Example #3
0
        public static SimulateGoalDocument ToDocument(this SimulateGoalVM simulateGoalVM)
        {
            var document = new SimulateGoalDocument()
            {
                Id             = simulateGoalVM.Id,
                AnnualPercente = simulateGoalVM.AnnualPercente,
                BeginValue     = simulateGoalVM.BeginValue,
                DateKind       = simulateGoalVM.DateKind,
                Contributions  = simulateGoalVM.Contributions?.ToDocument()
            };

            return(document);
        }
Example #4
0
        public async Task <IActionResult> Put(string id, SimulateGoalVM simulateGoalVM)
        {
            var result = await _walletService.AddAsync(simulateGoalVM);

            return(Ok(result));
        }