public async Task <GraphDataDto> GenGraphData(AutumnUserDto userInfo)
        {
            try
            {
                userInfo.ReturnRate = 0;
                var          countryData = _countryRepository.FirstOrDefault(userInfo.CountryId);
                GraphDataDto data        = new GraphDataDto()
                {
                    CurrentAge     = userInfo.Age,
                    DesRetSum      = userInfo.DesiredRetirementSum == null ? 0 : (double)userInfo.DesiredRetirementSum,
                    LifeExpectancy = countryData.LifeExpectancy,
                    LikRetLegacies = new List <double>(),
                    LikRetSums     = new List <double>(),
                    RetirementAges = new List <int>()
                };
                if (userInfo.RetirementGoalOptions == RetirementGoalsEnumDto.DesiredRetirementSum ||
                    userInfo.RetirementGoalOptions == RetirementGoalsEnumDto.DesiredRetirementIncome ||
                    userInfo.RetirementGoalOptions == RetirementGoalsEnumDto.DesiredRetirementAge)
                {
                    userInfo.DesiredLegacyAmount = 0;
                }
                for (int i = userInfo.Age + 1, j = 0; i < countryData.LifeExpectancy; i++)
                {
                    data.RetirementAges.Add(i);
                    switch (userInfo.RetirementGoalOptions)
                    {
                    //Variable legacy
                    case RetirementGoalsEnumDto.DesiredRetirementSum:

                        userInfo.DesiredRetirementIncome = FinancialCalculations.PMT((double)userInfo.ReturnRate, i - userInfo.Age, -(double)userInfo.DesiredRetirementSum, (double)userInfo.DesiredLegacyAmount) / 12;
                        userInfo.InitialNet = userInfo.InitialSaved - userInfo.InitialOwed;
                        //userInfo.RequiredSavings = FinancialCalculations.PMT((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.InitialNet, -(double)userInfo.DesiredRetirementSum) / 12;
                        userInfo.TotalMonthlySavings = userInfo.TotalMonthlyIncome - userInfo.TotalMonthlyExpences;
                        data.LikRetSums.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.TotalMonthlySavings * -12, (double)-userInfo.InitialNet) * (Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age)));
                        data.LikRetLegacies.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, countryData.LifeExpectancy - i, (double)userInfo.DesiredRetirementIncome * 12, -(double)data.LikRetSums[j]));

                        break;

                    //Variable legacy
                    case RetirementGoalsEnumDto.DesiredRetirementIncome:

                        userInfo.DesiredRetirementSum = FinancialCalculations.PV((double)userInfo.ReturnRate, countryData.LifeExpectancy - i, (double)userInfo.DesiredRetirementIncome * -12, (double)userInfo.DesiredLegacyAmount) * (Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age));
                        userInfo.InitialNet           = userInfo.InitialSaved - userInfo.InitialOwed;
                        //userInfo.RequiredSavings = FinancialCalculations.PMT((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.InitialNet, -(double)userInfo.DesiredRetirementSum) / 12;
                        userInfo.TotalMonthlySavings = userInfo.TotalMonthlyIncome - userInfo.TotalMonthlyExpences;
                        data.LikRetSums.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.TotalMonthlySavings * -12, (double)-userInfo.InitialNet) * Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age));
                        data.LikRetLegacies.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, countryData.LifeExpectancy - i, (double)userInfo.DesiredRetirementIncome * 12, -(double)data.LikRetSums[j]));

                        break;

                    //Variable age
                    case RetirementGoalsEnumDto.DesiredLegacyAmount:

                        userInfo.DesiredRetirementAge = i;
                        userInfo.DesiredRetirementSum = FinancialCalculations.PV((double)userInfo.ReturnRate, countryData.LifeExpectancy - i, (double)userInfo.DesiredRetirementIncome * -12, (double)userInfo.DesiredLegacyAmount) * (Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age));
                        userInfo.InitialNet           = userInfo.InitialSaved - userInfo.InitialOwed;
                        userInfo.TotalMonthlySavings  = userInfo.TotalMonthlyIncome - userInfo.TotalMonthlyExpences;
                        //userInfo.RequiredSavings = FinancialCalculations.PMT((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.InitialNet, -(double)userInfo.DesiredRetirementSum) / 12;
                        data.LikRetSums.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.InitialNet * -12, (double)-userInfo.InitialNet) * Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age));
                        //userInfo.LikelyRetirementAge = Math.Round((((double)userInfo.DesiredRetirementSum - (double)data.LikRetSums[j]) / (((double)userInfo.TotalMonthlySavings + (double)userInfo.DesiredRetirementIncome) * 12)) + i, MidpointRounding.AwayFromZero);

                        break;

                    //Variable legacy
                    case RetirementGoalsEnumDto.DesiredRetirementAge:

                        userInfo.DesiredRetirementSum = FinancialCalculations.PV((double)userInfo.ReturnRate, countryData.LifeExpectancy - i, (double)userInfo.DesiredRetirementIncome * -12, (double)userInfo.DesiredLegacyAmount) * (Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age));
                        userInfo.InitialNet           = userInfo.InitialSaved - userInfo.InitialOwed;
                        //userInfo.RequiredSavings = FinancialCalculations.PMT((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.InitialNet, -(double)userInfo.DesiredRetirementSum) / 12;
                        userInfo.TotalMonthlySavings = userInfo.TotalMonthlyIncome - userInfo.TotalMonthlyExpences;
                        data.LikRetSums.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, i - userInfo.Age, (double)userInfo.TotalMonthlySavings * -12, (double)-userInfo.InitialNet) * Math.Pow(1 + (double)userInfo.ReturnRate, i - userInfo.Age));
                        data.LikRetLegacies.Add(FinancialCalculations.FV((double)userInfo.ReturnRate, countryData.LifeExpectancy - i, (double)userInfo.DesiredRetirementIncome * 12, -(double)data.LikRetSums[j]));

                        break;

                    case RetirementGoalsEnumDto.PlaceToLiveAfterRetirement:

                        break;

                    default:

                        userInfo.DesiredRetirementAge = i;
                        userInfo.DesiredLegacyAmount  = 0;

                        break;
                    }
                }
                return(data);
            }
            catch (UserFriendlyException e)
            {
                throw new UserFriendlyException(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task CreateUser(AutumnUserDto input)
        {
            try
            {
                var user = ObjectMapper.Map <User>(input); //Passwords is not mapped (see mapping configuration)
                user.TenantId = null;

                await UserManager.InitializeOptionsAsync(AbpSession.TenantId);

                foreach (var validator in _passwordValidators)
                {
                    CheckErrors(await validator.ValidateAsync(UserManager, user, input.Password));
                }

                user.Password = _passwordHasher.HashPassword(user, input.Password);
                user.Surname  = "xyz";
                //Assign roles
                var role = await _roleManager.GetRoleByNameAsync(StaticRoleNames.Host.User);

                user.Roles              = new Collection <UserRole>();
                user.CreatorUserId      = null;
                user.DeleterUserId      = null;
                user.LastModifierUserId = null;
                user.Roles.Add(new UserRole(null, user.Id, role.Id));

                CheckErrors(await UserManager.CreateAsync(user));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get new user's Id.

                //Notifications
                await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(user.ToUserIdentifier());

                await _appNotifier.WelcomeToTheApplicationAsync(user);

                //Organization Units
                //await UserManager.SetOrganizationUnitsAsync(user, input.OrganizationUnits.ToArray());

                //Send activation email
                //if (input.SendActivationEmail)
                //{
                //    user.SetNewEmailConfirmationCode();
                //    await _userEmailer.SendEmailActivationLinkAsync(
                //        user,
                //        AppUrlService.CreateEmailActivationUrlFormat(AbpSession.TenantId),
                //        input.User.Password
                //    );
                //}

                var userRetirementPlan = ObjectMapper.Map <UserRetirementPlanDto>(input);
                userRetirementPlan.UserId     = user.Id;
                userRetirementPlan.ReturnRate = 0;
                var countryData = _countryRepository.FirstOrDefault((int)user.CountryId);
                switch (userRetirementPlan.RetirementGoalOptions)
                {
                //Variable legacy
                case RetirementGoalsEnumDto.DesiredRetirementSum:
                    if (userRetirementPlan.DesiredLegacyAmount == null)
                    {
                        userRetirementPlan.DesiredLegacyAmount = 0;
                    }

                    userRetirementPlan.DesiredRetirementIncome = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, -(double)userRetirementPlan.DesiredRetirementSum, (double)userRetirementPlan.DesiredLegacyAmount) / 12;
                    userRetirementPlan.InitialNet             = userRetirementPlan.InitialSaved - userRetirementPlan.InitialOwed;
                    userRetirementPlan.RequiredSavings        = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.InitialNet, -(double)userRetirementPlan.DesiredRetirementSum) / 12;
                    userRetirementPlan.TotalMonthlySavings    = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetirementPlan.LikelyRetirementSum    = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.TotalMonthlySavings * -12, (double)-userRetirementPlan.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.LikelyRetirementLegacy = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * 12, -(double)userRetirementPlan.LikelyRetirementSum);

                    break;

                //Variable legacy
                case RetirementGoalsEnumDto.DesiredRetirementIncome:
                    if (userRetirementPlan.DesiredLegacyAmount == null)
                    {
                        userRetirementPlan.DesiredLegacyAmount = 0;
                    }

                    userRetirementPlan.DesiredRetirementSum   = FinancialCalculations.PV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * -12, (double)userRetirementPlan.DesiredLegacyAmount) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.InitialNet             = userRetirementPlan.InitialSaved - userRetirementPlan.InitialOwed;
                    userRetirementPlan.RequiredSavings        = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.InitialNet, -(double)userRetirementPlan.DesiredRetirementSum) / 12;
                    userRetirementPlan.TotalMonthlySavings    = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetirementPlan.LikelyRetirementSum    = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.TotalMonthlySavings * -12, (double)-userRetirementPlan.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.LikelyRetirementLegacy = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * 12, -(double)userRetirementPlan.LikelyRetirementSum);

                    break;

                //Variable age
                case RetirementGoalsEnumDto.DesiredLegacyAmount:

                    userRetirementPlan.DesiredRetirementAge = countryData.RetirementAge;
                    userRetirementPlan.DesiredRetirementSum = FinancialCalculations.PV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * -12, (double)userRetirementPlan.DesiredLegacyAmount) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.InitialNet           = userRetirementPlan.InitialSaved - userRetirementPlan.InitialOwed;
                    userRetirementPlan.TotalMonthlySavings  = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetirementPlan.RequiredSavings      = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.InitialNet, -(double)userRetirementPlan.DesiredRetirementSum) / 12;
                    userRetirementPlan.LikelyRetirementSum  = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.InitialNet * -12, (double)-userRetirementPlan.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.LikelyRetirementAge  = Math.Round((((double)userRetirementPlan.DesiredRetirementSum - (double)userRetirementPlan.LikelyRetirementSum) / (((double)userRetirementPlan.TotalMonthlySavings + (double)userRetirementPlan.DesiredRetirementIncome) * 12)) + (double)userRetirementPlan.DesiredRetirementAge, MidpointRounding.AwayFromZero);

                    break;

                //Variable legacy
                case RetirementGoalsEnumDto.DesiredRetirementAge:
                    if (userRetirementPlan.DesiredLegacyAmount == null)
                    {
                        userRetirementPlan.DesiredLegacyAmount = 0;
                    }

                    userRetirementPlan.DesiredRetirementSum   = FinancialCalculations.PV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * -12, (double)userRetirementPlan.DesiredLegacyAmount) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.InitialNet             = userRetirementPlan.InitialSaved - userRetirementPlan.InitialOwed;
                    userRetirementPlan.RequiredSavings        = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.InitialNet, -(double)userRetirementPlan.DesiredRetirementSum) / 12;
                    userRetirementPlan.TotalMonthlySavings    = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetirementPlan.LikelyRetirementSum    = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetirementPlan.TotalMonthlySavings * -12, (double)-userRetirementPlan.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetirementPlan.LikelyRetirementLegacy = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * 12, -(double)userRetirementPlan.LikelyRetirementSum);

                    break;

                case RetirementGoalsEnumDto.PlaceToLiveAfterRetirement:

                    break;

                default:

                    userRetirementPlan.DesiredRetirementAge = countryData.RetirementAge;
                    userRetirementPlan.DesiredLegacyAmount  = 0;

                    break;
                }

                await _userRetirementPlanRepository.InsertAsync(ObjectMapper.Map <UserRetirementPlan>(userRetirementPlan));
            }
            catch (UserFriendlyException e)
            {
                throw new UserFriendlyException(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task UpdateUser(AutumnUserDto user)
        {
            try
            {
                var autumnUser = await UserManager.FindByIdAsync(AbpSession.UserId.ToString());

                autumnUser.Age          = user.Age;
                autumnUser.CountryId    = user.CountryId;
                autumnUser.EmailAddress = user.EmailAddress;
                autumnUser.Name         = user.Name;
                autumnUser.Gender       = (Gender)user.Gender;
                autumnUser.Surname      = "xyz";
                CheckErrors(await UserManager.UpdateAsync(autumnUser));
                var userRetiretmentData = await _userRetirementPlanRepository.GetAll().FirstOrDefaultAsync(r => r.UserId == AbpSession.UserId);

                userRetiretmentData.RetirementGoalOptions = (RetirementGoals)user.RetirementGoalOptions;
                userRetiretmentData.TotalMonthlyIncome    = user.TotalMonthlyIncome;
                userRetiretmentData.TotalMonthlyExpences  = user.TotalMonthlyExpences;
                userRetiretmentData.InitialSaved          = user.InitialSaved;
                userRetiretmentData.InitialOwed           = user.InitialOwed;

                userRetiretmentData.DesiredRetirementSum    = user.DesiredRetirementSum;
                userRetiretmentData.DesiredRetirementIncome = user.DesiredRetirementIncome;
                userRetiretmentData.DesiredLegacyAmount     = user.DesiredLegacyAmount;
                userRetiretmentData.DesiredRetirementAge    = user.DesiredRetirementAge;



                var userRetirementPlan = ObjectMapper.Map <UserRetirementPlanDto>(user);
                userRetirementPlan.UserId     = AbpSession.UserId.Value;
                userRetirementPlan.ReturnRate = 0;
                var countryData = _countryRepository.FirstOrDefault((int)user.CountryId);
                switch (userRetirementPlan.RetirementGoalOptions)
                {
                //Variable legacy
                case RetirementGoalsEnumDto.DesiredRetirementSum:
                    if (userRetirementPlan.DesiredLegacyAmount == null)
                    {
                        userRetirementPlan.DesiredLegacyAmount = 0;
                    }

                    userRetiretmentData.DesiredRetirementIncome = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, -(double)userRetirementPlan.DesiredRetirementSum, (double)userRetirementPlan.DesiredLegacyAmount) / 12;
                    userRetiretmentData.InitialNet             = userRetirementPlan.InitialSaved + userRetirementPlan.InitialOwed;
                    userRetiretmentData.RequiredSavings        = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.InitialNet, -(double)userRetirementPlan.DesiredRetirementSum) / 12;
                    userRetiretmentData.TotalMonthlySavings    = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetiretmentData.LikelyRetirementSum    = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.TotalMonthlySavings * -12, (double)-userRetiretmentData.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.LikelyRetirementLegacy = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetiretmentData.DesiredRetirementIncome * 12, -(double)userRetiretmentData.LikelyRetirementSum);

                    break;

                //Variable legacy
                case RetirementGoalsEnumDto.DesiredRetirementIncome:
                    if (userRetirementPlan.DesiredLegacyAmount == null)
                    {
                        userRetirementPlan.DesiredLegacyAmount = 0;
                    }

                    userRetiretmentData.DesiredRetirementSum   = FinancialCalculations.PV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * -12, (double)userRetirementPlan.DesiredLegacyAmount) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.InitialNet             = userRetirementPlan.InitialSaved + userRetirementPlan.InitialOwed;
                    userRetiretmentData.RequiredSavings        = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.InitialNet, -(double)userRetiretmentData.DesiredRetirementSum) / 12;
                    userRetiretmentData.TotalMonthlySavings    = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetiretmentData.LikelyRetirementSum    = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.TotalMonthlySavings * -12, (double)-userRetiretmentData.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.LikelyRetirementLegacy = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * 12, -(double)userRetiretmentData.LikelyRetirementSum);

                    break;

                //Variable age
                case RetirementGoalsEnumDto.DesiredLegacyAmount:

                    userRetiretmentData.DesiredRetirementAge = countryData.RetirementAge;
                    userRetiretmentData.DesiredRetirementSum = FinancialCalculations.PV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * -12, (double)userRetirementPlan.DesiredLegacyAmount) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.InitialNet           = userRetirementPlan.InitialSaved + userRetirementPlan.InitialOwed;
                    userRetiretmentData.TotalMonthlySavings  = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetiretmentData.RequiredSavings      = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.InitialNet, -(double)userRetiretmentData.DesiredRetirementSum) / 12;
                    userRetiretmentData.LikelyRetirementSum  = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.InitialNet * -12, (double)-userRetiretmentData.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.LikelyRetirementAge  = Math.Round((((double)userRetirementPlan.DesiredRetirementSum - (double)userRetiretmentData.LikelyRetirementSum) / (((double)userRetiretmentData.TotalMonthlySavings + (double)userRetirementPlan.DesiredRetirementIncome) * 12)) + (double)userRetirementPlan.DesiredRetirementAge, MidpointRounding.AwayFromZero);

                    break;

                //Variable legacy
                case RetirementGoalsEnumDto.DesiredRetirementAge:
                    if (userRetirementPlan.DesiredLegacyAmount == null)
                    {
                        userRetirementPlan.DesiredLegacyAmount = 0;
                    }

                    userRetiretmentData.DesiredRetirementSum   = FinancialCalculations.PV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * -12, (double)userRetirementPlan.DesiredLegacyAmount) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.InitialNet             = userRetirementPlan.InitialSaved + userRetirementPlan.InitialOwed;
                    userRetiretmentData.RequiredSavings        = FinancialCalculations.PMT((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.InitialNet, -(double)userRetiretmentData.DesiredRetirementSum) / 12;
                    userRetiretmentData.TotalMonthlySavings    = userRetirementPlan.TotalMonthlyIncome - userRetirementPlan.TotalMonthlyExpences;
                    userRetiretmentData.LikelyRetirementSum    = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age, (double)userRetiretmentData.TotalMonthlySavings * -12, (double)-userRetiretmentData.InitialNet) * (Math.Pow(1 + (double)userRetirementPlan.ReturnRate, (double)userRetirementPlan.DesiredRetirementAge - (double)user.Age));
                    userRetiretmentData.LikelyRetirementLegacy = FinancialCalculations.FV((double)userRetirementPlan.ReturnRate, countryData.LifeExpectancy - (double)userRetirementPlan.DesiredRetirementAge, (double)userRetirementPlan.DesiredRetirementIncome * 12, -(double)userRetiretmentData.LikelyRetirementSum);

                    break;

                case RetirementGoalsEnumDto.PlaceToLiveAfterRetirement:

                    break;

                default:

                    userRetiretmentData.DesiredRetirementAge = countryData.RetirementAge;
                    userRetiretmentData.DesiredLegacyAmount  = 0;

                    break;
                }

                await _userRetirementPlanRepository.UpdateAsync(userRetiretmentData);
            }
            catch (UserFriendlyException e)
            {
                throw new UserFriendlyException(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }