Exemplo n.º 1
0
        public async Task SavePreviousResultsAsync()
        {
            //Arrange
            var previousResultEntity = new PreviousResult();

            previousResultEntity.LifeOfProject           = 5;
            previousResultEntity.InitialCost             = 300000;
            previousResultEntity.LowerBoundDiscountRate  = 1;
            previousResultEntity.UpperBoundDiscountRate  = 15;
            previousResultEntity.DiscountRateIncrement   = 0.65;
            previousResultEntity.NetPresentValue         = 234553;
            previousResultEntity.PresentValueOfCashFlows = 17345;
            previousResultEntity.CreatedDate             = DateTime.UtcNow;

            previousResultEntity.CashFlows.Add(new CashFlows {
                Year  = 1,
                Value = 12345,
            });
            previousResultEntity.CashFlows.Add(new CashFlows
            {
                Year  = 2,
                Value = 24223,
            });
            previousResultEntity.CashFlows.Add(new CashFlows
            {
                Year  = 3,
                Value = 22345,
            });
            previousResultEntity.CashFlows.Add(new CashFlows
            {
                Year  = 4,
                Value = 52344,
            });
            previousResultEntity.CashFlows.Add(new CashFlows
            {
                Year  = 5,
                Value = 12623,
            });
            //Act
            _npvContext.AddPreviousResults(previousResultEntity);

            var saveChangesResult = await _npvContext.SaveEntityChangesAsync();

            //Assert
            Assert.IsTrue(saveChangesResult > 0);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SavePreviousResults(CalculationModel calculationModel)
        {
            if (calculationModel == null)
            {
                throw new Exception("The parameter calculationModel is null");
            }

            var netPresentValue = Convert.ToDecimal(_calculationService.CalculateNetPresentValue(calculationModel));

            var presentValueOfCashFlows = netPresentValue + calculationModel.InitialCost;

            var previousResult = new PreviousResult();

            previousResult.LifeOfProject           = calculationModel.LifeOfProject;
            previousResult.InitialCost             = calculationModel.InitialCost;
            previousResult.LowerBoundDiscountRate  = calculationModel.LowerBoundDiscountRate;
            previousResult.UpperBoundDiscountRate  = calculationModel.UpperBoundDiscountRate;
            previousResult.DiscountRateIncrement   = calculationModel.DiscountRateIncrement;
            previousResult.NetPresentValue         = netPresentValue;
            previousResult.PresentValueOfCashFlows = presentValueOfCashFlows;

            calculationModel?.CashFlows?.ForEach(x =>
            {
                previousResult.CashFlows.Add(new CashFlows {
                    Year  = x.Year,
                    Value = x.Value
                });
            });

            previousResult.CreatedDate = DateTime.UtcNow;

            _npvContext.AddPreviousResults(previousResult);

            var saveChangesResult = await _npvContext.SaveEntityChangesAsync();

            if (saveChangesResult > 0)
            {
                return(Ok(new { Success = true }));
            }

            return(StatusCode((int)HttpStatusCode.InternalServerError));
        }