Пример #1
0
        public List <Vacancy> Parse(string url)
        {
            try
            {
                var siteSettingsList = _webSiteSettingsRepository.GetWebSitesSettings();

                IWebSiteSettings webSiteSettings = null;

                foreach (var setting in siteSettingsList)
                {
                    if (url.Contains(setting.Domain))
                    {
                        webSiteSettings = setting;
                    }
                }

                if (webSiteSettings != null)
                {
                    List <Vacancy> vacancies = webSiteSettings.Parse(url);
                    _vacancyRepository.AddVacancies(vacancies);
                }
                return(_vacancyRepository.GetVacancies());
            }

            catch (Exception ex)
            {
                return(new List <Vacancy>());
            }
        }
Пример #2
0
        public async Task <IActionResult> GetVacancies([FromQuery] Params userParams)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(BadRequest("Please signed in to your account."));
            }

            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Something went wrong..."));
            }

            var currentlyLoginUserName = User.Identity.Name;
            var loggedInUser           = await _user.FindByEmailAsync(currentlyLoginUserName);

            var vacancies = await _repo.GetVacancies(loggedInUser, userParams);

            if (vacancies == null)
            {
                return(BadRequest("Something went wrong..."));
            }

            var returnVacancies = _mapper.Map <IEnumerable <ConciseVacancyDto> >(vacancies);

            return(Ok(returnVacancies));
        }
Пример #3
0
    public async Task <IPagedList <Vacancy> > GetVacancies(int page = 1, int pageSize = 10)
    {
        var key = $"vacancy{page}_{pageSize}";

        var result = _cache.Get(key) as IPagedList <Vacancy>;

        if (result == null)
        {
            var items = await _repository.GetVacancies(page, pageSize);

            var totalItemsCount = await _repository.GetVacanciesCount();

            result = new StaticPagedList <Vacancy>(items, page, pageSize, totalItemsCount);
            _cache.Set(key, result, GetMemoryCacheEntryOptions());
        }

        return(result);
    }
Пример #4
0
        public ViewResult Index(string sortOrder, string currentFilter, string searchString)
        {
            if (String.IsNullOrEmpty(searchString))
            {
                Vars.GetVacanciesFromHh();
            }

            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";

            ViewBag.CurrentFilter = searchString;

            var vacancies = vacancyRepository.GetVacancies().Select(s => s).Take(15);

            if (!String.IsNullOrEmpty(searchString))
            {
                vacancies = vacancies.Where(s => s.vacancy_name.ToUpper().Contains(searchString.ToUpper()));
            }
            switch (sortOrder)
            {
            case "name_desc":
                vacancies = vacancies.OrderByDescending(s => s.vacancy_name);
                break;

            case "Date":
                vacancies = vacancies.OrderBy(s => s.published_at);
                break;

            case "date_desc":
                vacancies = vacancies.OrderByDescending(s => s.published_at);
                break;

            case "employer_name":
                vacancies = vacancies.OrderByDescending(s => s.employer_name);
                break;

            default:      // Name ascending
                vacancies = vacancies.OrderBy(s => s.vacancy_name);
                break;
            }

            return(View(vacancies));
        }