Beispiel #1
0
        public IActionResult GetRateChartItem(int id)
        {
            var rateChartItem = _repository.GetRate(id);

            if (rateChartItem == null)
            {
                return(NotFound());
            }

            return(Ok(rateChartItem));
        }
        public IActionResult PutContractItem(string customerName, DateTime dob, string gender)
        {
            Customer customer = _repository.GetCustomerByName(customerName);

            if (customer == null)
            {
                _logger.LogInformation($"Customer with name {customerName} not found.");
                ModelState.AddModelError("Customer Name", "No Customer with this name!");
                return(BadRequest(ModelState));
            }
            var planType = _repository.GetCoveragePlan(customer.Country, customer.DateOfBirth);
            var age      = DateTime.Now.Year - dob.Year;

            if (planType == null)
            {
                _logger.LogInformation($"Suitable Coverage Plan for the provided parameters not found.");
                ModelState.AddModelError("Coverage Plan", "Coverage Plan not found!");
                return(BadRequest(ModelState));
            }
            object g       = null;
            Gender cgender = (Gender)
                             (Enum.TryParse(typeof(Gender), gender, true, out g) ? g : Gender.Other);
            var rate = _repository.GetRate(cgender, age, planType);

            if (rate == null)
            {
                _logger.LogInformation($"Rate not found for the Plan Id {planType.PlanId}.");
                ModelState.AddModelError("Rate", "Rate not found!");
                return(BadRequest(ModelState));
            }
            var contractItem = new ContractItem
            {
                CustomerId = customer.CustomerId,
                SaleDate   = DateTime.Now.Date,
                CoverageId = planType.PlanId,
                NetPrice   = rate.NetPrice
            };

            _repository.EditContract(contractItem);

            return(NoContent());
        }