public IActionResult Search(JourneySearchViewModel searchParams) { if (!ModelState.IsValid) { TempData.AddErrorMessage(WebConstants.ErrorTryAgain); return(RedirectToHome()); } if (searchParams == null) { TempData.AddErrorMessage(WebConstants.ErrorTryAgain); return(RedirectToHome()); } if (searchParams.StartPointX == 0 || searchParams.StartPointY == 0 || searchParams.EndPointX == 0 || searchParams.EndPointY == 0) { TempData.AddErrorMessage(WebConstants.MissingJourney); return(RedirectToHome()); } if (searchParams.SetOffTime < DateTime.Now) { TempData.AddErrorMessage(WebConstants.JourneyInThePast); return(RedirectToHome()); } List <JourneyListViewModel> result = new List <JourneyListViewModel>(); FindMatches(searchParams, ref result); return(View("Results", result)); }
private void FindMatches(JourneySearchViewModel searchParams, ref List <JourneyListViewModel> result) { //Set the search parameters double startSearchLat = (double)searchParams.StartPointX; double startSearchLon = (double)searchParams.StartPointY; double endSearchLat = (double)searchParams.EndPointX; double endSearchLon = (double)searchParams.EndPointY; DateTime searchDate = searchParams.SetOffTime; int searchRadius = searchParams.Radius; int currentUserId = GetCurrentUserAsync().Result.Id; IEnumerable <Journey> journeys = service.GetAll(j => j.SetOffTime.Date == searchDate.Date && j.Seats > j.Passengers.Count && j.DriverId != currentUserId); foreach (Journey journey in journeys) { if (journeyService.IsMatch(startSearchLat, startSearchLon, endSearchLat, endSearchLon, searchRadius, searchDate, journey)) { result.Add(mapper.Map <Journey, JourneyListViewModel>(journey)); } } }