Ejemplo n.º 1
0
        //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);
        }