/// <summary> /// For Inserts /// </summary> public static Need CreateFromViewModel(NeedsViewModel s) { Need respVal = new Need { PublishAnonymously = s.PublishAnonymously, Timestamp = DateTimeOffset.Now, //N.B for inserts StatusId = (int)PostStatus.UnderReview, //N.B for inserts ContactName = s.ContactName ?? "", JobTitle = s.JobTitle, Email = s.Email, PhoneNumber = s.PhoneNumber, OrganisationName = s.OrganisationName, Department = s.Department, OrgTypeId = (int)s.OrgType, OrgTypeOther = s.OrgTypeOther, TownOrCity = s.TownOrCity, AddressLineOne = s.AddressLineOne, AddressLineTwo = s.AddressLineTwo, Postcode = s.Postcode, TellUsMore = s.TellUsMore, }; respVal.NeedPpeTypes = s.PpeTypes.Where(nt => nt.Selected).Select(nt => NeedPpeType.Create_FromViewModel(nt, respVal)).ToList(); return(respVal); }
public ActionResult Index(NeedsViewModel vm) { try { //min 25,000 //max 500,000 //25,000 increments //calculate needs decimal insuredNeedsRate = Decimal.Divide(1.06M, 1.03M) - 1.00M; decimal spouseTaxRate = 0.25M; decimal inflationRate = 0.03M; var numKidsNeedFunding = GetDefaultIfNull(vm.numKidsNeedFunding); var collegeFunding = Decimal.Multiply(numKidsNeedFunding, (vm.schoolType == SCHOOLTYPES_PUBLIC ? 75772.00M : 169676.00M)); var lumpSumNeedsAtDeath = GetDefaultIfNull(vm.finalExpenses) + GetDefaultIfNull(vm.otherDebtExpenses) + GetDefaultIfNull(vm.mortgageExpenses) + collegeFunding; var incomeNeeds = vm.totalAnnualIncome; decimal currentInvestmentCapital = GetDefaultIfNull(vm.currentRetirementSavings) + GetDefaultIfNull(vm.currentSavings); decimal existingLifeInsurance = GetDefaultIfNull(vm.existingLifeInsuranceValue); decimal presentValueOfSpouseIncomeNeeds = Math.Abs(BusinessRulesClass.CalculatePresentValueOfIncomeNeeds(inflationRate, vm.spouseTotalAnnualIncome == null ? 0.0M : Decimal.Multiply((1 - spouseTaxRate), GetDefaultIfNull(vm.spouseTotalAnnualIncome)), vm.spouseYearsOfIncomeLeft == null ? 0 : vm.spouseYearsOfIncomeLeft.Value)); decimal presentValueOfIncomeNeeds = BusinessRulesClass.CalculatePresentValueOfIncomeNeeds(insuredNeedsRate, Decimal.Multiply(-1.0M, (GetDefaultIfNull(vm.totalAnnualIncome))), vm.yearsOfIncomeLeft == null ? 0 : vm.yearsOfIncomeLeft.Value); var overallNeeds = BusinessRulesClass.CalculateOverallNeeds(presentValueOfIncomeNeeds, lumpSumNeedsAtDeath, currentInvestmentCapital, existingLifeInsurance, presentValueOfSpouseIncomeNeeds); var nm = new NeedsModel() { collegeFunding = collegeFunding, currentInvestmentCapital = currentInvestmentCapital, existingLifeInsurance = existingLifeInsurance, incomeNeeds = GetDefaultIfNull(incomeNeeds), lumpSumNeedsAtDeath = lumpSumNeedsAtDeath, overallNeeds = overallNeeds, presentValueOfIncomeNeeds = presentValueOfIncomeNeeds, presentValueOfSpouseIncomeNeeds = presentValueOfSpouseIncomeNeeds }; vm.CoverageAmount = this.GetOverallNeedsBasedOnBand(overallNeeds); vm.needsModel = nm; return(View(vm)); //send to view with the results } catch (Exception ex) { TempData["ErrorMessage"] = ex.Message; var msg = "There was an error during the needs calculation."; vm.ViewMessages.Add(msg); return(View(vm)); } }
public NeedsViewModel CreateNeededModelForNeedIndex() { var needs = _itemFetcherService.GetNeeds(10); NeedsViewModel model = new NeedsViewModel() { Needs = needs, BudgetedForNeeds = _user.BudgetedForNeeds }; return(model); }
public void Modify(NeedsViewModel s) { PublishAnonymously = s.PublishAnonymously; ContactName = s.ContactName; JobTitle = s.JobTitle; Email = s.Email; PhoneNumber = s.PhoneNumber; OrganisationName = s.OrganisationName; Department = s.Department; OrgTypeId = (int)s.OrgType; OrgTypeOther = s.OrgTypeOther; TownOrCity = s.TownOrCity; Postcode = s.Postcode; TellUsMore = s.TellUsMore; }
public IActionResult RequestPpe([FromServices] DataContext dataContext, NeedsViewModel vm) { SimpleNotifier noty = notifier(); if (ModelState.IsValid) { Need need = Need.CreateFromViewModel(vm); dataContext.Needs.Add(need); dataContext.SaveChanges(currentUserName); noty.AddMessage(MsgTypes.Success, "Thanks you have been added to the database, we will be in contact in due course"); return(Redirect("/")); } else { noty.AddMessage(MsgTypes.Warning, "Problems saving details, please fix and try again"); return(View(vm)); } }
// GET: Needs public async Task <IActionResult> Index() { if (User.Identity.IsAuthenticated) { // Get the id of the current loggedin user string id = User.FindFirst(ClaimTypes.NameIdentifier).Value; // Get all needs that belong to this user NeedsViewModel allNeeds = new NeedsViewModel { GeneralNeeds = await _context.Needs.ToListAsync(), UserNeeds = _context.Needs.Where(need => need.OwnerId == id).ToList(), NeedsWithDonations = _context.Needs .Include(n => n.DonationNeeds) .ThenInclude(dn => dn.Donation) .ToList() }; // return the view with the needs passed in return(View(allNeeds)); } return(View(await _context.Needs.ToListAsync())); }
public ActionResult Index(NeedsViewModel vm) { try { // Determine eligibility //EligibilityInfo eligibility = BusinessRulesClass.IsEligible(vm.Age, vm.stateInfo.Name, vm.tobacco, vm.health, null == vm.ReplacementPolicy ? false : vm.ReplacementPolicy.Value); //if (eligibility.IsEligible) //{ //min 25,000 //max 500,000 //25,000 increments //calculate needs decimal insuredNeedsRate = Decimal.Divide(1.06M, 1.03M) - 1.00M; decimal spouseTaxRate = 0.25M; decimal inflationRate = 0.03M; var numKidsNeedFunding = GetDefaultIfNull(vm.numKidsNeedFunding); var collegeFunding = Decimal.Multiply(numKidsNeedFunding, (vm.schoolType == "PUBLIC" ? 75772.00M : 169676.00M)); var lumpSumNeedsAtDeath = GetDefaultIfNull(vm.finalExpenses) + GetDefaultIfNull(vm.otherDebtExpenses) + GetDefaultIfNull(vm.mortgageExpenses) + collegeFunding; var incomeNeeds = vm.totalAnnualIncome; decimal currentInvestmentCapital = GetDefaultIfNull(vm.currentRetirementSavings) + GetDefaultIfNull(vm.currentSavings); decimal existingLifeInsurance = GetDefaultIfNull(vm.existingLifeInsuranceValue); decimal presentValueOfSpouseIncomeNeeds = Math.Abs(BusinessRulesClass.CalculatePresentValueOfIncomeNeeds(inflationRate, vm.spouseTotalAnnualIncome == null ? 0.0M : Decimal.Multiply((1 - spouseTaxRate), GetDefaultIfNull(vm.spouseTotalAnnualIncome)), vm.spouseYearsOfIncomeLeft == null ? 0 : vm.spouseYearsOfIncomeLeft.Value)); decimal presentValueOfIncomeNeeds = BusinessRulesClass.CalculatePresentValueOfIncomeNeeds(insuredNeedsRate, Decimal.Multiply(-1.0M, (GetDefaultIfNull(vm.totalAnnualIncome))), vm.yearsOfIncomeLeft == null ? 0 : vm.yearsOfIncomeLeft.Value); var overallNeeds = BusinessRulesClass.CalculateOverallNeeds(presentValueOfIncomeNeeds, lumpSumNeedsAtDeath, currentInvestmentCapital, existingLifeInsurance, presentValueOfSpouseIncomeNeeds); var nm = new NeedsModel() { collegeFunding = collegeFunding, currentInvestmentCapital = currentInvestmentCapital, existingLifeInsurance = existingLifeInsurance, incomeNeeds = GetDefaultIfNull(incomeNeeds), lumpSumNeedsAtDeath = lumpSumNeedsAtDeath, overallNeeds = overallNeeds, presentValueOfIncomeNeeds = presentValueOfIncomeNeeds, presentValueOfSpouseIncomeNeeds = presentValueOfSpouseIncomeNeeds }; vm.CoverageAmount = this.GetOverallNeedsBasedOnBand(overallNeeds); vm.needsModel = nm; return(View(vm)); //send to view with the results /*} * else * { * TempData["ContactViewModel"] = new ContactViewModel { DenialMessage = eligibility.EligibilityMessage, IsReplacementReject = eligibility.IsReplacememtReject, State = eligibility.State }; * return RedirectToActionPermanent("Contact", "Contact"); * }*/ } catch (Exception ex) { TempData["ErrorMessage"] = ex.Message; var msg = "There was an error during the needs calculation."; vm.ViewMessages.Add(msg); return(View(vm)); } }
public ActionResult Index() { NeedsViewModel modl = new NeedsViewModel(); return(View(modl)); }