示例#1
0
        /// <inheritdoc/>
        public async Task UpdateVacancies()
        {
            VacancySearchResult vacanciesResult = await _headHunterClient.GetVacancies();

            IEnumerable <Vacancy> vacancies = await _vacanciesRepository.GetVacancies();

            foreach (Item vacancyResult in vacanciesResult.Items)
            {
                if (!vacancies.Any(v => v.ExternalId == vacancyResult.Id.ToString() && v.SavingDate == DateTime.Today))
                {
                    var vacancy = new Vacancy();
                    vacancy.ExternalId = vacancyResult.Id.ToString();
                    vacancy.SavingDate = DateTime.Today;
                    vacancy.Title      = vacancyResult.Name;
                    vacancy.Company    = await _vacanciesRepository.GetCompany(vacancyResult.Employer.Id.ToString());

                    vacancy.Company.Name = vacancyResult.Employer.Name;
                    if (vacancyResult.Salary != null)
                    {
                        vacancy.Salary.From     = vacancyResult.Salary.From;
                        vacancy.Salary.To       = vacancyResult.Salary.To;
                        vacancy.Salary.Currency = GetCurrency(vacancyResult.Salary.Currency);
                    }

                    vacancy.PublicationDate = DateTime.Parse(vacancyResult.PublishedAt);

                    await _vacanciesRepository.SaveVacancy(vacancy);
                }
            }
        }