public IActionResult Index(Analyse analyse) { analyse = _analyseRepository.GetById(analyse.AnalyseId, Soort.Subsidie); analyse.UpdateTotalen(_analyseRepository); SubsidieViewModel model = MaakModel(analyse); return(View(model)); }
public void TestOpslaan_RepoGooitException_RedirectsToIndex() { _analyseRepository.Setup(r => r.Save()).Throws(new Exception()); SubsidieViewModel model = new SubsidieViewModel(); var result = _controller.Opslaan(_analyse, model) as RedirectToActionResult; Assert.Equal("Index", result?.ActionName); _exceptionLogRepository.Verify(r => r.Add(It.IsAny <ExceptionLog>()), Times.Once); _exceptionLogRepository.Verify(r => r.Save(), Times.Once); }
public void TestOpslaan_RedirectsToIndex() { SubsidieViewModel model = new SubsidieViewModel { Bedrag = "" + 25000 }; var result = _controller.Opslaan(_analyse, model) as RedirectToActionResult; Assert.Equal("Index", result?.ActionName); var expected = Convert.ToDecimal(model.Bedrag); var actual = Convert.ToDecimal(_analyse.Subsidie.Bedrag); Assert.Equal(expected, actual); }
public IActionResult Opslaan(Analyse analyse, SubsidieViewModel model) { try { if (ModelState.IsValid) { analyse = _analyseRepository.GetById(analyse.AnalyseId, Soort.Subsidie); // de baat bestaat reeds: DecimalConverter dc = new DecimalConverter(); Subsidie baat = new Subsidie { Type = model.Type, Soort = model.Soort, Bedrag = dc.ConvertToDecimal(model.Bedrag) }; analyse.Subsidie = baat; analyse.DatumLaatsteAanpassing = DateTime.Now; _analyseRepository.Save(); TempData["message"] = Meldingen.OpslaanSuccesvolBaat; } } catch (Exception e) { if (e is ArgumentException || e is FormatException) { TempData["error"] = e.Message; } else { _exceptionLogRepository.Add(new ExceptionLog(e, "Subsidie", "Opslaan -- POST --")); _exceptionLogRepository.Save(); TempData["error"] = Meldingen.OpslaanFoutmeldingKost; return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }