private PolicyReturned PoliciyLife(Policy policy) { var response = new PolicyReturned(); if (policy.DateOfBirth == DateTime.MinValue) { response.Message = "Life policy must include Date of Birth."; return(response); } if (policy.DateOfBirth < DateTime.Today.AddYears(-100)) { response.Message = "Centenarians are not eligible for coverage."; return(response); } if (policy.Amount == 0) { response.Message = "Life policy must include an Amount."; return(response); } var age = DateTime.Today.Year - policy.DateOfBirth.Year; if (policy.DateOfBirth.Month == DateTime.Today.Month && DateTime.Today.Day < policy.DateOfBirth.Day || DateTime.Today.Month < policy.DateOfBirth.Month) { age--; } var baseRate = policy.Amount * age / 200; if (policy.IsSmoker) { response.Rating = baseRate * 2; return(response); } response.Rating = baseRate; return(response); }
public PolicyReturned Rate() { var response = new PolicyReturned(); SaveLog($"Start consuming the method: {DateTime.Now}"); var policy = ReadObject <Policy>(configuration["policyFile"]); if (policy == null) { response.Message = "The archive is empty or dosen't have correct values"; return(response); } switch (policy.Type) { case PolicyType.Auto: if (string.IsNullOrEmpty(policy.Make)) { response.Message = "Auto policy must specify Make"; return(response); } if (policy.Make == "BMW") { if (policy.Deductible < 500) { response.Rating = 1000m; } response.Rating = 900m; } break; case PolicyType.Land: if (policy.BondAmount == 0 || policy.Valuation == 0) { response.Message = "Land policy must specify Bond Amount and Valuation."; return(response); } if (policy.BondAmount < 0.8m * policy.Valuation) { response.Message = "Insufficient bond amount."; return(response); } response.Rating = policy.BondAmount * 0.05m; break; case PolicyType.Life: response = PoliciyLife(policy); break; default: response.Message = "Unknown policy type"; break; } PersistenceData(response, configuration["persitenceFile"]); SaveLog($"Rating completed: {DateTime.Now}"); return(response); }