public ActionResult FilteredRestaurants(double? latitude, double? longitude, string search, int? categoryId, double distance = 1) { var zoom = 15; if (distance > 2 && distance <= 5) { zoom = 14; } else if (distance >= 5 && distance <= 8) { zoom = 13; } else if (distance >= 8) { zoom = 12; } if (latitude != null && longitude != null) { var restaurants = this.restaurants.FilterRestaurants((double)latitude, (double)longitude, distance, search, categoryId).To<RestaurantMapViewModel>().ToList(); if (restaurants == null) { return this.Redirect("/"); } var model = new RestaurantMapFilterViewModel { Zoom = zoom, Restaurants = restaurants }; return this.PartialView("~/Areas/Regular/Views/GoogleMaps/_GoogleMapsFilterListRestaurantsPartial.cshtml", model); } return this.Redirect("/"); }
public ActionResult FilteredRestaurants(RestaurantFilterRequestViewModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/")); } if (model.Search == null) { model.Search = string.Empty; } if (model.Distance == null || model.Distance <= 0) { model.Distance = 1; } var restaurants = this.restaurants.FilterRestaurants(model.Latitude, model.Longitude, (double)model.Distance, model.Search, model.CategoryId) .To <RestaurantMapViewModel>() .ToList(); if (restaurants == null) { return(this.Redirect("/")); } int zoom = this.googleMapsService.GetBestGoogleMapsZoom((double)model.Distance); var mapModel = new RestaurantMapFilterViewModel { Zoom = zoom, Restaurants = restaurants }; return(this.PartialView("~/Areas/Regular/Views/GoogleMaps/_GoogleMapsFilterListRestaurantsPartial.cshtml", mapModel)); }