Esempio n. 1
0
        public HomePageResponseViewModel Post([FromBody] HomePageRequestViewModel viewModel)
        {
            Dictionary <string, string> errors;
            HomePageResponseViewModel   responseViewModel = new HomePageResponseViewModel();

            try
            {
                errors = viewModel.Validate();

                if (errors.Count > 0)
                {
                    responseViewModel.Errors         = errors;
                    responseViewModel.MonthlyPremium = 0;
                }
                else
                {
                    responseViewModel.Errors         = errors;
                    responseViewModel.MonthlyPremium = Math.Round(_premiumService.CalculateDeathPremium(viewModel.SumInsured,
                                                                                                        viewModel.Age,
                                                                                                        viewModel.OccupationId)
                                                                  , 2);
                }
            }
            catch (Exception exception)
            {
                responseViewModel.Errors.Add("", "An error occured while processing your request");
                responseViewModel.MonthlyPremium = 0;
                _logger.LogError(exception, exception.Message);
            }

            return(responseViewModel);
        }
        public void EnsureThatSumInsuredIsGreaterThanZeroInHomeRequestViewModel()
        {
            HomePageRequestViewModel model = new HomePageRequestViewModel()
            {
                Name         = "Sam",
                DateOfBirth  = DateTime.Now.ToShortDateString(),
                Age          = 35,
                OccupationId = 5,
                SumInsured   = 0
            };

            var errors = model.Validate();

            Assert.IsTrue(errors.Count == 1);
        }