public ImportRestaurant GetRestaurantsFromApi(string serviceBaseUrl, RestaurantImportSettings settings)
 {
     var page = 1;
     var results = new ImportRestaurant { TotalResults = 51 };
     while (results.TotalResults > page * 50)
     {
         var apiUrl = GenerateRestaurantApiUrl(serviceBaseUrl, settings.PublisherKey, settings.Latitude, settings.Longitude, settings.Radius, page);
         var objRequest = WebRequest.Create(apiUrl);
         var objResponse = objRequest.GetResponse();
         string strResult;
         using (var sr = new StreamReader(objResponse.GetResponseStream()))
         {
             strResult = sr.ReadToEnd();
         }
         var data = System.Web.Helpers.Json.Decode(strResult);
         results.TotalResults = data.results.total_hits;
         results.FirstHit = data.results.first_hit;
         results.LastHit = data.results.last_hit;
         results.Page = data.results.page;
         foreach (var item in data.results.locations)
         {
             if (results.Restaurants.ToList().Find(f => f.RestaurantName == item.name) == null)
             {
                 results.Restaurants.Add(new RestaurantToImport { RestaurantName = item.name, Selected = false, PreferredDayOfWeek = null });
             }
         }
         page++;
     }
     results.Restaurants = results.Restaurants.OrderBy(f => f.RestaurantName).ToList();
     results.Restaurants = CheckAlreadyImported(results.Restaurants);
     return results;
 }
 public PartialViewResult Search(string term)
 {
     ImportRestaurant results;
     if (Session[SessionName] == null)
     {
         results = _importRestaurantLogic.GetRestaurantsFromApi(ConfigurationManager.AppSettings.Get("RestaurantProviderURL"), GetDefaultImportSetting());
     }
     else
     {
         results = (ImportRestaurant)Session[SessionName];
         results.Restaurants = _importRestaurantLogic.CheckAlreadyImported(results.Restaurants);
     }
     var model = new ImportRestaurant { TotalResults = results.TotalResults, Page = results.Page, FirstHit = results.FirstHit, LastHit = results.LastHit, Restaurants = results.Restaurants };
     if (!string.IsNullOrWhiteSpace(term) && term.Length > 1)
         model.Restaurants = model.Restaurants.Where(f => f.RestaurantName.ToLower().Contains(term.ToLower())).ToList();
     GenerateDropDownLists();
     return PartialView("_ImportRestaurantsList", model);
 }
 public PartialViewResult SaveImports(ImportRestaurant model)
 {
     if (model != null && model.Restaurants.Any())
     {
         var restaurantsToImport = new List<Restaurant>();
         model.Restaurants = _importRestaurantLogic.CheckAlreadyImported(model.Restaurants);
         foreach (var restaurant in model.Restaurants)
         {
             if (!restaurant.AlreadyImported)
                 restaurantsToImport.Add(restaurant.ToDomainModel());
         }
         _restaurantLogic.SaveOrUpdateAll(restaurantsToImport.ToArray());
         model.Restaurants = _importRestaurantLogic.CheckAlreadyImported(model.Restaurants);
     }
     GenerateDropDownLists();
     return PartialView("~/Views/Restaurants/_ImportRestaurantsList.cshtml", model);
 }