/// <summary>
        /// Obtener una lista de Trabajos paginada por Ubicacion.
        /// </summary>
        /// <param name="parameter">Objeto con los parametros necesarios para realizar la consulta.</param>
        /// <returns>Objeto que representa una lista de datos paginados</returns>
        public IPagedList <JobOpportunity> GetAllJobOpportunitiesByLocationPaged(JobOpportunityPagingParameter parameter)
        {
            IPagedList <JobOpportunity> result;

            if (parameter.Page <= 0)
            {
                parameter.Page = 1;
            }

            if (parameter.PageSize <= 0)
            {
                parameter.PageSize = 15;
            }

            var jobs = DbSet;

            if (parameter.SelectedLocation <= 0)
            {
                result = jobs.Include(x => x.Location)
                         .OrderByDescending(x => x.Id)
                         .ToPagedList(parameter.Page, parameter.PageSize);
            }
            else
            {
                result = DbSet.Include(x => x.Location)
                         .Where(x => x.LocationId.Equals(parameter.SelectedLocation))
                         .OrderByDescending(x => x.Id)
                         .ToPagedList(parameter.Page, parameter.PageSize);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obtener una lista de Empleos paginada por Ubicacion.
        /// </summary>
        /// <param name="parameter">Objeto con los parametros necesarios para realizar la consulta.</param>
        /// <returns>Objeto que representa una lista de datos paginados</returns>
        public IPagedList <JobOpportunity> GetAllJobOpportunitiesPagedByFilters(JobOpportunityPagingParameter parameter)
        {
            IPagedList <JobOpportunity> result = new PagedList <JobOpportunity>(null, 1, 15);

            if (parameter.Page <= 0)
            {
                parameter.Page = 1;
            }

            if (parameter.PageSize <= 0)
            {
                parameter.PageSize = 15;
            }

            var jobs = DbSet
                       .Include(x => x.JobOpportunityLocation);

            jobs = jobs
                   .OrderByDescending(x => x.Likes)
                   .ThenByDescending(x => x.Id);

            //Filter by JobCategory
            jobs = jobs.Where(x => x.Category == parameter.JobCategory);

            if (parameter.IsRemote)
            {
                jobs = jobs.Where(x => x.IsRemote);
            }

            //Filter using FTS if keyword is not empty
            if (!string.IsNullOrWhiteSpace(parameter.Keyword))
            {
                jobs = jobs.FullTextSearch(parameter.Keyword);
            }

            //if no location selected just return pagination
            if (string.IsNullOrWhiteSpace(parameter.SelectedLocationPlaceId))
            {
                result = jobs.ToPagedList(parameter.Page, parameter.PageSize);

                return(result);
            }

            //Query using Haversine formula ref.: http://www.wikiwand.com/en/Haversine_formula

            var locations = GetNearbyJobOpportunityLocations(parameter.SelectedLocationLatitude,
                                                             parameter.SelectedLocationLongitude, parameter.LocationDistance);

            if (!locations.Any())
            {
                return(result);
            }

            result = (from jo in jobs
                      where locations.Contains(jo.JobOpportunityLocationId.Value)
                      select jo).ToPagedList(parameter.Page, parameter.PageSize);

            return(result);
        }
        /// <summary>
        /// Obtener una lista de Empleos paginada por Ubicacion.
        /// </summary>
        /// <param name="parameter">Objeto con los parametros necesarios para realizar la consulta.</param>
        /// <returns>Objeto que representa una lista de datos paginados</returns>
        public IPagedList <JobOpportunity> GetAllJobOpportunitiesPagedByFilters(JobOpportunityPagingParameter parameter)
        {
            IPagedList <JobOpportunity> result;

            if (parameter.Page <= 0)
            {
                parameter.Page = 1;
            }

            if (parameter.PageSize <= 0)
            {
                parameter.PageSize = 15;
            }

            var jobs = DbSet.Include(x => x.Location);

            if (parameter.JobCategory != JobCategory.All)
            {
                jobs = jobs.Where(x => x.Category == parameter.JobCategory);
            }

            if (parameter.IsRemote)
            {
                jobs = jobs.Where(x => x.IsRemote);
            }

            jobs = jobs.OrderByDescending(x => x.Id);

            if (parameter.SelectedLocation <= 0)
            {
                if (!string.IsNullOrWhiteSpace(parameter.Keyword))
                {
                    result = jobs.FullTextSearch(parameter.Keyword)
                             .ToPagedList(parameter.Page, parameter.PageSize);
                }
                else
                {
                    result = jobs.ToPagedList(parameter.Page, parameter.PageSize);
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(parameter.Keyword))
                {
                    result = jobs.Where(x => x.LocationId.Equals(parameter.SelectedLocation))
                             .FullTextSearch(parameter.Keyword)
                             .ToPagedList(parameter.Page, parameter.PageSize);
                }
                else
                {
                    result = jobs
                             .Where(x => x.LocationId.Equals(parameter.SelectedLocation))
                             .ToPagedList(parameter.Page, parameter.PageSize);
                }
            }

            return(result);
        }
        // GET: /JobOpportunity/
        public ActionResult Index(JobOpportunityPagingParameter model)
        {
            var viewModel = GetSearchViewModel(model);

            var jobOpportunities = _jobOpportunityService.GetAllJobOpportunitiesPagedByFilters(model);

            viewModel.Result = jobOpportunities;

            return(View(viewModel));
        }
        /// <summary>
        /// Transform JobOpportunityPagingParameter into JobOpportunitySearchViewModel with Locations
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private JobOpportunitySearchViewModel GetSearchViewModel(JobOpportunityPagingParameter model)
        {
            var locations = _locationService.GetLocationsWithDefault();

            var viewModel = new JobOpportunitySearchViewModel
            {
                Locations        = locations.ToSelectList(l => l.Id, l => l.Name, model.SelectedLocation),
                SelectedLocation = model.SelectedLocation,
                JobCategory      = model.JobCategory,
                Keyword          = model.Keyword,
                IsRemote         = model.IsRemote
            };

            return(viewModel);
        }
Ejemplo n.º 6
0
        public ActionResult Index(JobOpportunityPagingParameter model)
        {
            var viewModel = GetSearchViewModel(model);

            if (!string.IsNullOrWhiteSpace(viewModel.SelectedLocationName) &&
                string.IsNullOrWhiteSpace(viewModel.SelectedLocationPlaceId))
            {
                ModelState.AddModelError("SelectedLocationName", "");
                return(View(viewModel).WithError("Debe seleccionar una Localidad para buscar."));
            }

            var jobOpportunities = _jobOpportunityService.GetAllJobOpportunitiesPagedByFilters(model);

            viewModel.Result = jobOpportunities;

            return(View(viewModel));
        }
        public void Index_ReturnsRequestedDataCorrectly_LocationEmpty()
        {
            // Arrange
            var param = new JobOpportunityPagingParameter {
                SelectedLocationName      = string.Empty,
                SelectedLocationLatitude  = "18.686868",
                SelectedLocationLongitude = "-69.454545",
                SelectedLocationPlaceId   = "111",
                JobCategory = JobCategory.All,
                Keyword     = "myKeyword",
                IsRemote    = true
            };

            var jobCategoriesCount = new[] { new JobCategoryCountDto() }.ToList();
            var jobOpportunityList = new[] { new JobOpportunity() }.ToPagedList(1, 1);

            _jobOpportunityService.GetMainJobCategoriesCount().Returns(jobCategoriesCount);
            _jobOpportunityService.GetAllJobOpportunitiesPagedByFilters(param).Returns(jobOpportunityList);

            // Act
            var result = (ViewResult)_sut.Index(param);

            // Assert
            _sut.ModelState.IsValid.Should().BeTrue();

            _jobOpportunityService.Received(1).GetMainJobCategoriesCount();
            _jobOpportunityService.Received(1).GetAllJobOpportunitiesPagedByFilters(param);

            var model = (JobOpportunitySearchViewModel)result.Model;

            model.SelectedLocationLatitude.Should().BeEmpty();
            model.SelectedLocationLongitude.Should().BeEmpty();
            model.SelectedLocationPlaceId.Should().BeEmpty();
            model.SelectedLocationName.Should().BeEmpty();
            model.JobCategory.Should().Be(param.JobCategory);
            model.Keyword.Should().Be(param.Keyword);
            model.IsRemote.Should().Be(param.IsRemote);
            model.CategoriesCount.Should().BeSameAs(jobCategoriesCount);
            model.Result.Should().BeSameAs(jobOpportunityList);
        }
        public void Index_LocationNameNotNull_PlaceIdNull_ReturnsViewWithError()
        {
            // Arrange
            var param = new JobOpportunityPagingParameter {
                SelectedLocationPlaceId = null,
                SelectedLocationName    = "Guachupita",
                JobCategory             = JobCategory.All,
                Keyword  = "myKeyword",
                IsRemote = true
            };

            var jobCategoriesCount = new[] { new JobCategoryCountDto() }.ToList();

            _jobOpportunityService.GetMainJobCategoriesCount().Returns(jobCategoriesCount);

            // Act
            var result = (AlertDecoratorResult)_sut.Index(param);

            // Assert
            _jobOpportunityService.Received(1).GetMainJobCategoriesCount();
            _jobOpportunityService.DidNotReceiveWithAnyArgs().GetAllJobOpportunitiesPagedByFilters(param);

            _sut.ModelState.IsValid.Should().BeFalse();
            _sut.ModelState.Should().ContainKey("SelectedLocationName");

            result.AlertClass.Should().Be("alert-danger");
            result.Message.Should().Be("Debe seleccionar una Localidad para buscar.");
            var viewResult = (ViewResult)result.InnerResult;
            var model      = (JobOpportunitySearchViewModel)viewResult.Model;

            model.SelectedLocationLatitude.Should().Be(param.SelectedLocationLatitude);
            model.SelectedLocationLongitude.Should().Be(param.SelectedLocationLongitude);
            model.SelectedLocationPlaceId.Should().BeNull();
            model.SelectedLocationName.Should().Be(param.SelectedLocationName);
            model.JobCategory.Should().Be(param.JobCategory);
            model.Keyword.Should().Be(param.Keyword);
            model.IsRemote.Should().Be(param.IsRemote);
            model.CategoriesCount.Should().BeSameAs(jobCategoriesCount);
            model.Result.Should().BeEmpty();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Transform JobOpportunityPagingParameter into JobOpportunitySearchViewModel with Locations
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private JobOpportunitySearchViewModel GetSearchViewModel(JobOpportunityPagingParameter model)
        {
            if (string.IsNullOrWhiteSpace(model.SelectedLocationName))
            {
                model.SelectedLocationLatitude  = string.Empty;
                model.SelectedLocationLongitude = string.Empty;
                model.SelectedLocationPlaceId   = string.Empty;
            }

            var viewModel = new JobOpportunitySearchViewModel {
                SelectedLocationPlaceId   = model.SelectedLocationPlaceId,
                SelectedLocationName      = model.SelectedLocationName,
                SelectedLocationLongitude = model.SelectedLocationLongitude,
                SelectedLocationLatitude  = model.SelectedLocationLatitude,
                JobCategory     = model.JobCategory,
                Keyword         = model.Keyword,
                IsRemote        = model.IsRemote,
                CategoriesCount = _jobOpportunityService.GetMainJobCategoriesCount(),
            };

            return(viewModel);
        }
 public IPagedList <JobOpportunity> GetAllJobOpportunitiesPagedByFilters(JobOpportunityPagingParameter parameter)
 {
     return(_jobOpportunityRepository.GetAllJobOpportunitiesPagedByFilters(parameter));
 }