private async Task <bool> UploadEmployment(Person person, SSG_SearchRequest request, SSG_Person ssg_person, int?providerDynamicsID, CancellationToken concellationToken) { if (person.Employments == null) { return(true); } try { foreach (var employment in person.Employments) { EmploymentEntity e = _mapper.Map <EmploymentEntity>(employment); e.SearchRequest = request; e.InformationSource = providerDynamicsID; e.Person = ssg_person; SSG_Employment ssg_employment = await _searchRequestService.CreateEmployment(e, concellationToken); if (employment.Employer != null) { foreach (var phone in employment.Employer.Phones) { SSG_EmploymentContact p = _mapper.Map <SSG_EmploymentContact>(phone); p.Employment = ssg_employment; await _searchRequestService.CreateEmploymentContact(p, concellationToken); } } } return(true); } catch (Exception ex) { _logger.LogError(ex.Message); return(false); } }
private async Task <bool> UploadEmployment(bool inUpdateProcess = false) { if (_personSought.Employments == null) { return(true); } _logger.LogDebug($"Attempting to create employment records for PersonSought."); foreach (var employment in _personSought.Employments) { EmploymentEntity e = _mapper.Map <EmploymentEntity>(employment); e.SearchRequest = _uploadedSearchRequest; e.InformationSource = InformationSourceType.Request.Value; e.Person = _uploadedPerson; e.IsCreatedByAgency = true; if (inUpdateProcess) { e.UpdateDetails = "New Employment"; } SSG_Employment ssg_employment = await _searchRequestService.CreateEmployment(e, _cancellationToken); if (employment.Employer != null) { foreach (var phone in employment.Employer.Phones) { EmploymentContactEntity p = _mapper.Map <EmploymentContactEntity>(phone); p.Employment = ssg_employment; if (inUpdateProcess) { e.UpdateDetails = "New EmploymentContact"; } await _searchRequestService.CreateEmploymentContact(p, _cancellationToken); } } } _logger.LogInformation("Create employment records for SearchRequest successfully"); return(true); }
private async Task <bool> UploadEmployment( ) { if (_foundPerson.Employments == null) { return(true); } try { _logger.LogDebug($"Attempting to create found employment records for SearchRequest[{_searchRequest.SearchRequestId}]"); foreach (var employment in _foundPerson.Employments) { EmploymentEntity e = _mapper.Map <EmploymentEntity>(employment); e.SearchRequest = _searchRequest; e.InformationSource = _providerDynamicsID; e.Person = _returnedPerson; SSG_Employment ssg_employment = await _searchRequestService.CreateEmployment(e, _cancellationToken); if (employment.Employer != null) { foreach (var phone in employment.Employer.Phones) { EmploymentContactEntity p = _mapper.Map <EmploymentContactEntity>(phone); p.Employment = ssg_employment; await _searchRequestService.CreateEmploymentContact(p, _cancellationToken); } } await CreateResultTransaction(ssg_employment); } return(true); } catch (Exception ex) { _logger.LogError(ex.Message); return(false); } }
//this function is never been used. private async Task <bool> UpdateEmployment() { if (_personSought.Employments == null) { return(true); } _logger.LogDebug($"Attempting to update employment records for PersonSought."); SSG_Employment originalEmployment = _uploadedPerson.SSG_Employments?.FirstOrDefault( m => m.InformationSource == InformationSourceType.Request.Value && m.IsCreatedByAgency); if (_personSought.Employments.Count() > 0) { EmploymentEntity employ = _mapper.Map <EmploymentEntity>(_personSought.Employments.ElementAt(0)); if (originalEmployment == null) { await UploadEmployment(); } else { IDictionary <string, object> updatedFields = originalEmployment.Clone().GetUpdateEntries(employ); if (updatedFields.ContainsKey("ssg_countrytext")) //country changed { SSG_Country country = await _searchRequestService.GetEmploymentCountry(employ.CountryText, _cancellationToken); updatedFields.Add("ssg_LocationCountry", country); } if (updatedFields.ContainsKey("ssg_countrysubdivision_text")) //subdivision changed { SSG_CountrySubdivision subdivision = await _searchRequestService.GetEmploymentSubdivision(employ.CountrySubdivisionText, _cancellationToken); updatedFields.Add("ssg_CountrySubDivision", subdivision); } if (updatedFields.Count > 0) { await _searchRequestService.UpdateEmployment(originalEmployment.EmploymentId, updatedFields, _cancellationToken); _logger.LogInformation("Update Employment records for SearchRequest successfully"); } Employer employer = _personSought.Employments.ElementAt(0).Employer; if (employer != null && employer.Phones != null && employer.Phones.Count() > 0) { SSG_Employment existedEmployment = await _searchRequestService.GetEmployment(originalEmployment.EmploymentId, _cancellationToken); existedEmployment.IsDuplicated = true; foreach (var phone in employer.Phones) { EmploymentContactEntity p = _mapper.Map <EmploymentContactEntity>(phone); p.Employment = existedEmployment; await _searchRequestService.CreateEmploymentContact(p, _cancellationToken); } } } } return(true); }