示例#1
0
        public IActionResult Index(Analyse analyse)
        {
            analyse = _analyseRepository.GetById(analyse.AnalyseId, Soort.ExtraOmzet);
            analyse.UpdateTotalen(_analyseRepository);

            ExtraOmzetViewModel model = MaakModel(analyse);

            return(View(model));
        }
        public void TestOpslaan_RepoGooitException_RedirectsToIndex()
        {
            _analyseRepository.Setup(r => r.Save()).Throws(new Exception());
            ExtraOmzetViewModel model = new ExtraOmzetViewModel();

            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()
        {
            ExtraOmzetViewModel model = new ExtraOmzetViewModel
            {
                JaarbedragOmzetverlies = "" + 25000,
                Besparing = "" + 10
            };

            var result = _controller.Opslaan(_analyse, model) as RedirectToActionResult;

            Assert.Equal("Index", result?.ActionName);

            var expectedJaarbedrag = Convert.ToDecimal(model.JaarbedragOmzetverlies);
            var actualJaarbedrag   = Convert.ToDecimal(_analyse.ExtraOmzet.JaarbedragOmzetverlies);
            var expectedBesparing  = Convert.ToDecimal(model.Besparing);
            var actualBesparing    = Convert.ToDecimal(_analyse.ExtraOmzet.Besparing);

            Assert.Equal(expectedJaarbedrag, actualJaarbedrag);
            Assert.Equal(expectedBesparing, actualBesparing);
        }
示例#4
0
        public IActionResult Opslaan(Analyse analyse, ExtraOmzetViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    analyse = _analyseRepository.GetById(analyse.AnalyseId, Soort.ExtraOmzet);
                    DecimalConverter dc   = new DecimalConverter();
                    ExtraOmzet       baat = new ExtraOmzet
                    {
                        Type  = model.Type,
                        Soort = model.Soort,
                        JaarbedragOmzetverlies = dc.ConvertToDecimal(model.JaarbedragOmzetverlies),
                        Besparing = dc.ConvertToDecimal(model.Besparing)
                    };

                    analyse.ExtraOmzet             = 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, "ExtraOmzet", "Opslaan -- GET --"));
                    _exceptionLogRepository.Save();
                    TempData["error"] = Meldingen.OpslaanFoutmeldingKost;
                    return(RedirectToAction("Index"));
                }
            }

            return(RedirectToAction("Index"));
        }