public InsurancePolicyViewModel GetPolicyByInsurerPhone(string phone) { InsurancePolicyViewModel policyViewModel = null; using (var context = _factory.Create()) { var insurer = context.Insurers.First(ins => ins.Phone == phone); if (insurer == null) { return(null); } var insPolicy = context.InsurancePolicies.First(insP => insP.InsurerGuid == insurer.InsurancePolicyGuid); policyViewModel = insPolicy.MapPolicy(); } return(policyViewModel); }
public InsurancePolicyViewModel GetPolicyByInsurerPhone(string phone) { InsurancePolicyViewModel result = new InsurancePolicyViewModel(); for (int i = 0; i < _dataProviders.Count; i++) { _connectionService.SetCurrentDatabase(_databases[i]); if (result.Guid == Guid.Empty) { result = _dataProviders[i].GetPolicyByInsurerPhone(phone); } else { result = _dataProviders[i].GetPolicyByInsurerPhone(phone).MergePolicies(result); } } return(result); }
public static InsurancePolicyViewModel MergePolicies(this InsurancePolicyViewModel one, InsurancePolicyViewModel two) { if (one.Guid == Guid.Empty) { return(two); } InsurancePolicyViewModel resultPolicy = new InsurancePolicyViewModel { Guid = one.Guid, Number = one.Number, AgentName = one.AgentName, IsActive = two.IsActive, DateFrom = one.DateFrom, DateTill = one.DateTill, Insurer = one.Insurer, Beneficiaries = one.Beneficiaries }; if (resultPolicy.DateFrom == default(DateTime) || resultPolicy.DateTill == default(DateTime)) { resultPolicy.DateFrom = two.DateFrom; resultPolicy.DateTill = two.DateTill; resultPolicy.IsActive = one.IsActive; } resultPolicy.IsActive = DateTime.Now >= resultPolicy.DateFrom && DateTime.Now <= resultPolicy.DateTill ? true : false; if (resultPolicy.AgentName == null) { resultPolicy.AgentName = two.AgentName; } if (resultPolicy.Insurer.Phone == null) { resultPolicy.Insurer = two.Insurer; } if (resultPolicy.Beneficiaries == null || resultPolicy.Beneficiaries.Count == 0) { resultPolicy.Beneficiaries = two.Beneficiaries; } return(resultPolicy); }
/// <summary> /// Initializes a new instance of the InsuranceInformationView class. /// </summary> public InsuranceInformationView() { InitializeComponent(); _viewModel = ((InsurancePolicyViewModel)DataContext); _viewModel.ApplicationService = this; }