public static ResultViewModel MapToViewModel(NPVCriteria criteria) { var resultVM = new ResultViewModel() { ReferenceId = criteria.ReferenceId, CashFlows = criteria.CashFlows.Split(',') .Select(x => Convert.ToDecimal(x)) .ToList(), InitialValue = criteria.InitialValue, LowerBoundDiscountRate = criteria.LowerBoundDiscountRate * 100, UpperBoundDiscountRate = criteria.UpperBoundDiscountRate * 100, DiscountRateIncrement = criteria.DiscountRateIncrement * 100, ErrorMessage = criteria.ErrorMessage }; resultVM.Results = criteria.Results.Select(x => new ResultListItemViewModel() { DiscountRate = x.DiscountRate * 100, NPV = x.NPV } ).OrderBy(x => x.DiscountRate).ToList(); return(resultVM); }
public async Task <IActionResult> PutNPVCriteria(int id, NPVCriteria nPVCriteria) { if (id != nPVCriteria.ReferenceId) { return(BadRequest()); } _context.Entry(nPVCriteria).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NPVCriteriaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <NPVCriteria> > PostNPVCriteria(NPVCriteria nPVCriteria) { nPVCriteria.ComputeNPVForAllDiscounts(); _context.Criterias.Add(nPVCriteria); await _context.SaveChangesAsync(); return(CreatedAtAction("GetNPVCriteria", new { id = nPVCriteria.ReferenceId }, nPVCriteria)); }
public NPVCriteria MapToModel() { var criteria = new NPVCriteria() { CashFlows = string.Join(",", this.CashFlows), InitialValue = Convert.ToDecimal(this.InitialValue), LowerBoundDiscountRate = Convert.ToDecimal(this.LowerBoundDiscountRate) / 100, UpperBoundDiscountRate = Convert.ToDecimal(this.UpperBoundDiscountRate) / 100, DiscountRateIncrement = Convert.ToDecimal(this.DiscountRateIncrement) / 100 }; return(criteria); }
public async Task <ActionResult <NPVCriteria> > GetNPVCriteria(int id) { //var nPVCriteria = await _context.Criterias.FindAsync(id); var nPVCriteria = await _context.Criterias .Include(x => x.Results) .FirstOrDefaultAsync(x => x.ReferenceId == id); if (nPVCriteria == null) { nPVCriteria = new NPVCriteria() { ErrorMessage = "Reference Id not found." }; } return(nPVCriteria); }