public Task <Contracts> AddContracts(Contracts contracts) { if (db != null && !string.IsNullOrEmpty(contracts.Name) && !string.IsNullOrEmpty(contracts.Address) && !string.IsNullOrEmpty(contracts.Country)) { //get plan CoveragePlan coveragePlan = db.CoveragePlan.Where(x => x.EligibilityCountry == contracts.Country).FirstOrDefault(); //find Age from DOB int dboyear = contracts.Dob.Value.Year; int Age = DateTime.Today.Year - contracts.Dob.Value.Year; string converageAge = string.Empty; if (Age < 40) { converageAge = "<= 40"; } else { converageAge = ">40"; } RateChart rateChart = db.RateChart.Where(x => x.Gender == contracts.Gender && x.CoveragePlan == coveragePlan.Plan && x.Age == converageAge).FirstOrDefault(); if (rateChart != null) { //insert to Contracts table contracts.CoveragePlan = coveragePlan.Plan; contracts.NetPrice = rateChart.NetPrice; contracts.SaleDate = DateTime.Now; db.Contracts.Add(contracts); db.SaveChanges(); } return(Task.FromResult(contracts)); } return(null); }
/// <summary> /// Approves/Rejectes beat submitted by user. /// </summary> /// <param name="coverageCollection">The coverage collection.</param> /// <returns></returns> public bool ApproveRejectBeat(Dictionary <int, int> coverageCollection) { bool isSuccess = false; SystemSetting systemSetting = SmartDostDbContext.SystemSettings.FirstOrDefault(k => k.SettingID > 0); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { foreach (KeyValuePair <int, int> item in coverageCollection) { CoveragePlan coveragePlan = SmartDostDbContext.CoveragePlans.SingleOrDefault(c => c.CoverageID == item.Key); if (coveragePlan != null && coveragePlan.CoverageID > 0) { DateTime firstwindowfirst = CustomFormatDate(systemSetting.CoveragePlanFirstWindow.Substring(0, 8)); DateTime firstwindowsecond = CustomFormatDate(systemSetting.CoveragePlanFirstWindow.Substring(9, 8)); DateTime secondwindowfirst = CustomFormatDate(systemSetting.CoveragePlanSecondWndow.Substring(0, 8)); DateTime secondwindowsecond = CustomFormatDate(systemSetting.CoveragePlanSecondWndow.Substring(9, 8)); coveragePlan.StatusID = item.Value; if (coveragePlan.StatusID == 1) { coveragePlan.Remarks = "Beat Approved"; } else if (coveragePlan.StatusID == 2) { coveragePlan.Remarks = "Beat Rejected"; } coveragePlan.ModifiedDate = DateTime.Now.Date; if (!(coveragePlan.CoverageDate.Date >= firstwindowfirst && coveragePlan.CoverageDate.Date <= firstwindowsecond) || !(coveragePlan.CoverageDate.Date >= secondwindowfirst && coveragePlan.CoverageDate.Date <= secondwindowsecond)) { if (item.Value == 1) { SmartDostDbContext.UserSystemSettings.Add(new UserSystemSetting() { UserID = coveragePlan.UserID, IsAPKLoggingEnabled = false, CoverageExceptionWindow = null, IsCoverageException = true, CreatedDate = DateTime.Now, CreatedBy = coveragePlan.CreatedBy, ModifiedDate = null, ModifiedBy = null, IsDeleted = false }); } } } isSuccess = SmartDostDbContext.SaveChanges() > 0 ? true : false; } scope.Complete(); } return(isSuccess); }
//[HttpPut] //[Route("UpdateCustomer/{id}")] public IActionResult UpdateCustomer(long id, [FromBody] Customer customer) { try { if (customer == null) { return(BadRequest("Customer is null.")); } Customer customerToUpdate = _dataRepository.Get(id); if (customerToUpdate == null) { return(NotFound("The Customer record couldn't be found.")); } CoveragePlan cPlan = null; if (!string.IsNullOrEmpty(customer.CustomerCountry)) { if ((customer.CustomerCountry.ToLower() == "usa") || (customer.CustomerCountry.ToLower() == "can")) { cPlan = _coverageDataRepository.GetAll().Where(cp => (cp.EligibilityCountry == customer.CustomerCountry) && (customer.SaleDate >= cp.EligibilityDateFrom) && (customer.SaleDate <= cp.EligibilityDateTo)).FirstOrDefault(); } else { cPlan = _coverageDataRepository.GetAll().Where(cp => (cp.EligibilityCountry.ToLower() == "other") && (customer.SaleDate >= cp.EligibilityDateFrom) && (customer.SaleDate <= cp.EligibilityDateTo)).FirstOrDefault(); } } if (cPlan != null) { customer.CoveragePlan = cPlan.CoveragePlanName; int customerage = (int)(DateTime.UtcNow - customer.CustomerDateOfBirth).Value.TotalDays / 365; RateChart rc = _rateChartDataRepository.GetAll().Where(rc => (rc.CustomerGender == customer.CustomerGender) && (rc.CustomerAgeFrom <= customerage) && (rc.CustomerAgeTo >= customerage)).FirstOrDefault(); if (rc != null) { customer.NetPrice = rc.NetPrice; } } else { customer.CoveragePlan = " "; } _dataRepository.Update(customerToUpdate, customer); return(NoContent()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private RateChart RateChart(Contact contact) { CoveragePlan coveragePlan = _appDbContext.CoveragePlans.Include(c => c.RateCharts).FirstOrDefault(c => c.EligibilityCountry.ToLower() == contact.Country.ToLower()); if (coveragePlan == null) { coveragePlan = _appDbContext.CoveragePlans.Include(c => c.RateCharts).FirstOrDefault(c => c.IsDefault); } // Age on Sales Date List <RateChart> filterByCountry = coveragePlan.RateCharts.ToList(); int age = contact.SaleDate.Year - contact.DOB.Year; List <RateChart> filteredByGender = filterByCountry.Where(r => r.Gender == contact.Gender).ToList(); RateChart filterbyAge = filteredByGender.FirstOrDefault(r => age > r.AgeAbove) ?? filteredByGender.FirstOrDefault(r => age < r.AgeBelow); return(filterbyAge); }
//[Route("SaveCustomer")] public IActionResult SaveCustomer([FromBody] Customer customer) { try { if (customer == null) { return(BadRequest("Customer is null.")); } CoveragePlan cPlan = null; if (!string.IsNullOrEmpty(customer.CustomerCountry)) { if ((customer.CustomerCountry.ToLower() == "usa") || (customer.CustomerCountry.ToLower() == "can")) { cPlan = _coverageDataRepository.GetAll().Where(cp => (cp.EligibilityCountry == customer.CustomerCountry) && (customer.SaleDate >= cp.EligibilityDateFrom) && (customer.SaleDate <= cp.EligibilityDateTo)).FirstOrDefault(); } else { cPlan = _coverageDataRepository.GetAll().Where(cp => (cp.EligibilityCountry.ToLower() == "other") && (customer.SaleDate >= cp.EligibilityDateFrom) && (customer.SaleDate <= cp.EligibilityDateTo)).FirstOrDefault(); } } if (cPlan != null) { customer.CoveragePlan = cPlan.CoveragePlanName; int customerage = (int)(DateTime.UtcNow - customer.CustomerDateOfBirth).Value.TotalDays / 365; RateChart rc = _rateChartDataRepository.GetAll().Where(rc => (rc.CustomerGender == customer.CustomerGender) && (rc.CustomerAgeFrom <= customerage) && (rc.CustomerAgeTo >= customerage)).FirstOrDefault(); if (rc != null) { customer.NetPrice = rc.NetPrice; } } else { customer.CoveragePlan = " "; } _dataRepository.Add(customer); return(CreatedAtRoute( "Get", new { Id = customer.CustomerId }, customer)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
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."); }
public Contract CreateContract(ContractDetails contractDetails) { Contract contract = new Contract(); try { Random r = new Random(); CoveragePlan coveragePlan = GetCoveragePlan(contractDetails); int age = GetAge(contractDetails.CustomerDateOfBirth); int netPrice = GetNetPrice(coveragePlan.CoveragePlanType.ToUpper(), age, contractDetails.CustomerGender); if (coveragePlan != null) { contract = new Contract { ContractId = "LIC" + r.Next().ToString(), 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.Add(contract); } } catch (Exception Ex) { //Log exception } return(contract); }