// GET: /JobOpportunity/
        public ActionResult Index(string selectedLocation = "")
        {
            var jobList = _databaseContext.JobOpportunities
                .OrderByDescending(e => e.PublishedDate)
                .ToList();

            var locations = _databaseContext.JobOpportunities
                .Select(d => d.Location)
                .Distinct()
                .ToList();

            locations.Insert(0, "Todas las locaciones");

            if (!String.IsNullOrEmpty(selectedLocation)
                && selectedLocation != "Todas las locaciones")
            {
                jobList = jobList
                    .Where(j => j.Location == selectedLocation)
                    .ToList();
            }

            var vm = new JobOpportunitySearchViewModel {
                JobOpportunities = jobList,
                Locations = locations
            };

            if (!vm.JobOpportunities.Any())
                return RedirectToAction("Index", "Home");

            return View(vm);
        }
        // GET: /JobOpportunity/
        public ActionResult Index(int selectedLocation = 0, int page = 1, int pageSize = 15)
        {
            var locations = _locationRepository.GetAllLocations();

            locations.Insert(0, new Location { Id = 0, Name = "Todas" });

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

            var jobOpportunities =
                _jobRepository.GetAllJobOpportunitiesByLocationPaged(new JobOpportunityPagingParameter
                {
                    SelectedLocation = selectedLocation,
                    PageSize = pageSize,
                    Page = page
                });

            viewModel.Result = jobOpportunities;
            ViewBag.SelectedLocation = selectedLocation;

            return View(viewModel);
        }
        /// <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;
        }
        /// <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;
        }