Example #1
0
        public ServiceJobPostFilterDataResult GetJobPostsAndFilterData(ServiceJobPostSearchInputModel searchInputModel)
        {
            var jobPostsResult = this.GetJobPosts(searchInputModel);
            var result         = this._modelMapper.Map <ServiceJobPostListResult, ServiceJobPostFilterDataResult>(jobPostsResult);

            if (result.HasFailed)
            {
                return(result);
            }
            try
            {
                var repoCategoryResults       = this._jobCategoryRepository.GetJobCategories();
                var repoEmploymentTypeResults = this._employmentTypeRepository.GetEmploymentTypes();
                var repoLocationResults       = this._locationRepository.GetLocations();
                result.JobCategories   = this._modelMapper.Map <IEnumerable <RepositoryCategoryResult>, IEnumerable <ServiceCategoryResult> >(repoCategoryResults);
                result.EmploymentTypes = this._modelMapper.Map <IEnumerable <RepositoryEmploymentTypeResult>, IEnumerable <ServiceEmploymentTypeResult> >(repoEmploymentTypeResults);
                result.Locations       = this._modelMapper.Map <IEnumerable <RepositoryLocationResult>, IEnumerable <ServiceLocationResult> >(repoLocationResults);
            }
            catch (Exception exc)
            {
                // Normally, should be logged
                result.HasFailed = true;
            }
            return(result);
        }
Example #2
0
        public ServiceJobPostListResult GetJobPosts(ServiceJobPostSearchInputModel searchInputModel)
        {
            var result = new ServiceJobPostListResult();

            if (searchInputModel.ItemsPerPage <= 0)
            {
                searchInputModel.ItemsPerPage = this._defaultItemsPerPage;
            }
            if (searchInputModel.PageNumber <= 0)
            {
                searchInputModel.PageNumber = 1;
            }
            var itemsPerPage = searchInputModel.ItemsPerPage;
            var repositorySearchInputModel = this._modelMapper.Map <ServiceJobPostSearchInputModel, RepositoryJobPostSearchInputModel>(searchInputModel);

            repositorySearchInputModel.Take = itemsPerPage;
            repositorySearchInputModel.Skip = (searchInputModel.PageNumber - 1) * itemsPerPage;
            try
            {
                result.TotalCount = this._jobPostRepository.GetJobPostCount(repositorySearchInputModel);
                result.PageCount  = (result.TotalCount + itemsPerPage - 1) / itemsPerPage;
                var jobPosts = this._jobPostRepository.GetJobPosts(repositorySearchInputModel);
                result.JobPosts  = this._modelMapper.Map <IEnumerable <RepositoryJobPostResult>, IEnumerable <ServiceJobPostResult> >(jobPosts);
                result.HasFailed = false;
            }
            catch (Exception exc)
            {
                // Normally, should log the error using library like ELMAH
                result.HasFailed = true;
            }
            return(result);
        }