コード例 #1
0
        public IActionResult OnPost()
        {
            dto.CashFlows = new List <CashFlowDTO>();

            for (int i = 0; i < Request.Form["y.Id"].Count; i++)
            {
                dto.CashFlows.Add(new CashFlowDTO
                {
                    Id     = Convert.ToInt32(Request.Form["y.Id"][i]),
                    Amount = string.IsNullOrEmpty(Request.Form["y.Amount"][i]) ? 0 : Convert.ToDouble(Request.Form["y.Amount"][i])
                });
            }
            NpvValidate   validate = new NpvValidate();
            NpvCalculator calc     = new NpvCalculator(validate);

            dto = calc.Compute(dto);

            if (ModelState.IsValid)
            {
                var npv = mapper.Map <Npv>(dto);
                npvData.Update(npv);

                return(RedirectToPage("./Detail", new { npvId = dto.NpvId }));
            }
            else
            {
                ModelState.AddModelError("error", "An error occured");
            }

            return(Page());
        }
コード例 #2
0
ファイル: Compute.cshtml.cs プロジェクト: toastedcoke/Finance
        public IActionResult OnPost()
        {
            for (int i = 0; i < Request.Form["n.Id"].Count; i++)
            {
                dto.CashFlows.Add(new CashFlowDTO
                {
                    Amount    = string.IsNullOrEmpty(Request.Form["n.Amount"][i]) ? 0 : Convert.ToDouble(Request.Form["n.Amount"][i]),
                    NpvAmount = string.IsNullOrEmpty(Request.Form["n.NpvAmount"][i]) ? 0 : Convert.ToDouble(Request.Form["n.NpvAmount"][i])
                });
            }
            if (ModelState.IsValid)
            {
                var npv = mapper.Map <Npv>(dto);

                if (dto.NpvId > 0)
                {
                    npvData.Update(npv);
                }
                else
                {
                    npvData.Add(npv);
                }

                return(RedirectToPage("./Detail", new { npvId = npv.NpvId }));
            }

            return(RedirectToPage("./Error"));
        }