Exemple #1
0
        public async Task <bool> ImportAsync(ApiDto api, Dto.CompanyDto company, PersonalDataResponse personalData, JobDataResponse jobData, List <MailBodyDto> mailBodyList)
        {
            var persons    = personalData == null ? new List <Person>() : personalData.SoapenvEnvelope.Body.ApiVersionPersons.Persons.ToList();
            var jobs       = jobData == null ? new List <JobDataWithComp>() : jobData.SoapenvEnvelope.Body.ApiVersionJobs.JobDataWithCompList.ToList();
            int count      = 1;
            var httpClient = HttpClientHelper.Get(api);
            var imported   = true;

            foreach (var person in persons)
            {
                var progressMessage = $"Importing {count++} of {persons.Count}.";
                var userId          = Guid.Empty;
                var externalId      = person.Emplid.Text.ToString();
                var userName        = person.SubNames.NameDisplay.Text;
                var job             = jobs.FirstOrDefault(j => j.Job.Emplid.Text.ToString(CultureInfo.InvariantCulture) == externalId);
                if (job == null)
                {
                    await LogHelper.SaveLogAsync(httpClient, company.Code, company.CompanyId, Updater.MyStatusId, "User", userName, $"-- Not Imported - Job data must exists for employeeid {externalId} --", progressMessage, JsonConvert.SerializeObject(person));

                    imported = false;
                    continue;
                }
                var department = await GetDepartmentAsync(httpClient, company.CompanyId, job.Department.Deptid.Text);

                if (department == null)
                {
                    await ApiHelper.SaveLogAsync(httpClient, company.Code, company.CompanyId, Updater.MyStatusId, "User", userName, $"Department does not exists for external id {job.Department.Deptid.Text}.", progressMessage, JsonConvert.SerializeObject(person));

                    continue;
                }
                var isActive = job.Job.EmplStatus.Text == "A";
                var documentUserFieldValueDtos = await GetUserIdByHrLinkIdAsync(httpClient, person.Emplid.Text.ToString());

                if (documentUserFieldValueDtos.Count > 1)
                {
                    await ApiHelper.SaveLogAsync(httpClient, company.Code, company.CompanyId, Updater.MyStatusId, "User", userName, $"Exists several users with {person.Emplid.Text} HRLinkID.", progressMessage, JsonConvert.SerializeObject(person));

                    return(false);
                }
                if (documentUserFieldValueDtos.Count == 1)
                {
                    var user = await GetUserAsync(httpClient, documentUserFieldValueDtos[0].DocumentId);

                    externalId = user.ExternalId;
                    userId     = user.Id;
                }
                else
                {
                    externalId = (externalId.Length == 10 && externalId.Substring(2, 2) == "00") ? externalId.Remove(2, 2) : externalId;
                }
                var employeeDto = await SaveEmployeeAsync(httpClient, company, externalId, userName, isActive, progressMessage, mailBodyList);

                if (employeeDto == null)
                {
                    imported = false;
                    continue;
                }
                var savedUserTypology = await SaveUserTypologyAsync(httpClient, company, department.Id, job, progressMessage);

                if (!savedUserTypology)
                {
                    imported = false;
                    continue;
                }
                var savedUserDto = await SaveUserAsync(httpClient, company, userId, externalId, userName, isActive, person, job, employeeDto.Id, progressMessage, mailBodyList);

                if (savedUserDto == null)
                {
                    imported = false;
                    continue;
                }
                var documentUserFieldValueBatchPutModel = new DocumentUserFieldValueBatchPutModel
                {
                    DocumentId              = savedUserDto.Id,
                    DocumentTypeName        = "User",
                    DocumentUserFieldValues = new List <DocumentUserFieldValue>()
                };
                documentUserFieldValueBatchPutModel.DocumentUserFieldValues.Add(new DocumentUserFieldValue {
                    ColumnName = "HRLinkId", Value = person.Emplid.Text.ToString(), ColumnDataTypeId = (int)ColumnDataType.Varchar50
                });
                await SaveDocumentUserFieldValueAsync(httpClient, company, documentUserFieldValueBatchPutModel, progressMessage);
            }
            return(imported);
        }
Exemple #2
0
        private async Task SaveDocumentUserFieldValueAsync(HttpClient httpClient, Dto.CompanyDto companyDto, DocumentUserFieldValueBatchPutModel model, string progressMessage)
        {
            HttpContent contentPost = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
            var         response    = await httpClient.PutAsync("/api/documentUserFieldValues", contentPost);

            if (response.IsSuccessStatusCode)
            {
                await ApiHelper.SaveLogAsync(httpClient, companyDto.Code, companyDto.CompanyId, Updater.MyStatusId, "Document User Fields", "", "-- Updated --", progressMessage, JsonConvert.SerializeObject(model));

                return;
            }
            await ApiHelper.SaveLogAsync(httpClient, companyDto.Code, companyDto.CompanyId, Updater.MyStatusId, "Document User Fields", "", response.Content.ReadAsStringAsync().Result, progressMessage, JsonConvert.SerializeObject(model));
        }