Example #1
0
        public string UpdateContract(string contractId, ContractDetails contractDetails)
        {
            Contract contract = new Contract();

            try
            {
                Contract contractToUpdate = _InsuranceRepository.Get(contractId);

                if (contractToUpdate == null)
                {
                    return("The Contract record couldn't be found.");
                }

                CoveragePlan coveragePlan = GetCoveragePlan(contractDetails);
                // int a = Utility.
                int age = GetAge(contractDetails.CustomerDateOfBirth);

                int netPrice = GetNetPrice(coveragePlan.CoveragePlanType.ToUpper(), age, contractDetails.CustomerGender);

                if (coveragePlan != null)
                {
                    contract = new Contract
                    {
                        ContractId          = contractId,
                        CustomerName        = contractDetails.CustomerName,
                        CustomerAddress     = contractDetails.CustomerAddress.City,
                        CustomerGender      = contractDetails.CustomerGender,
                        CustomerCountry     = contractDetails.CustomerAddress.Country,
                        CustomerDateofbirth = contractDetails.CustomerDateOfBirth,
                        SaleDate            = contractDetails.SaleDate,
                        CoveragePlan        = coveragePlan.CoveragePlanType,
                        NetPrice            = netPrice
                    };
                }
                _InsuranceRepository.Update(contractToUpdate, contract);
            }
            catch (Exception Ex)
            {
                return("Failed to update contract.");
            }
            return("Contract updated successfully.");
        }