public NPV GenerateNPV(NPV nPV) { double npv; string[] cashFlow = nPV.CashFlows.Split(','); NPV npvItem = new NPV(); npvItem.CashFlows = nPV.CashFlows; npvItem.UpperBoundDiscountRate = nPV.UpperBoundDiscountRate; npvItem.LowerBoundDiscountRate = nPV.LowerBoundDiscountRate; npvItem.DiscountRateIncrement = nPV.DiscountRateIncrement; using (var context = new NPVContext()) { db.NPVItemResult.RemoveRange(db.NPVItemResult.Where(c => c.NPVId == nPV.ID)); db.SaveChanges(); for (double y = nPV.LowerBoundDiscountRate; y <= nPV.UpperBoundDiscountRate; y += nPV.DiscountRateIncrement) { for (int i = 0; i < cashFlow.Length; i++) { int period = i + 1; npv = Convert.ToInt32(cashFlow[i]) / (1 + Math.Pow((y / 100), period)); context.NPVItemResult.Add(new NPVItemResult { CashFlow = cashFlow[i], Discount = y, Period = period, NPVResult = npv, NPVId = nPV.ID }); } } context.SaveChanges(); } return(npvItem); }
public NPVController(NPVContext context) { _context = context; }
public NPVController(NPVContext dbContext) { this.dbContext = dbContext; }