Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,LowerBoundDiscountRate,UpperBoundDiscountRate,DiscountRateIncrement,CashFlows,NPVs,DateModified")] NPV nPV)
        {
            if (ModelState.IsValid)
            {
                db.NPV.Add(nPV);
                nPV.DateModified = DateTime.Now;

                db.SaveChanges();
                GenerateNPV(nPV);

                return(RedirectToAction("Index"));
            }

            return(View(nPV));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public IActionResult Post([FromBody] NPVQuery value)
        {
            var result = CalculateNPV(value);

            dbContext.Add <NPVQuery>(result);
            dbContext.SaveChanges();

            return(Ok(result));
        }
Exemplo n.º 4
0
        public Calculation SaveCalculation(ParametersVM parameters, IEnumerable <BaseSingleNPVCalculation> NPVs)
        {
            Calculation npvc = new Calculation
            {
                CalculationDate        = DateTime.Now,
                DiscountRateIncrement  = parameters.DiscountRateIncrement,
                InitialValue           = parameters.InitialValue,
                LowerBoundDiscountRate = parameters.LowerBoundDiscountRate,
                UpperBoundDiscountRate = parameters.UpperBoundDiscountRate
            };

            dbContext.NPVCalculations.Add(npvc);
            dbContext.SaveChanges();

            SaveCashflows(parameters.Cashflows, npvc.ID);
            SaveSingleNPVCalculations(NPVs, npvc.ID);

            return(npvc);
        }