Beispiel #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());
        }
Beispiel #2
0
        public IActionResult OnGet()
        {
            try
            {
                dto = TempData.Get <NpvDTO>("npvDTO");

                if (dto == null)
                {
                    return(RedirectToPage("./NotFound"));
                }

                NpvValidate   validate = new NpvValidate();
                NpvCalculator calc     = new NpvCalculator(validate);
                dto = calc.Compute(dto);

                return(Page());
            }
            catch (Exception e)
            {
                return(RedirectToPage("./Error"));
            }
        }