public async Task <IActionResult> Index(int?region)
        {
            Search <Location> search = new Search <Location>
            {
                Results = (region is null || region == 0) ?
                          await ApiClient.GetLocationsAsync() :
                          await ApiClient.GetLocationsByRegionAsync((int)region),
                Regions      = await ApiClient.GetRegionsAsync(),
                FilterOption = (region is null) ? 0 : (int)region
            };

            try
            {
                string             userstr = TempData.Peek("User").ToString();
                User               user    = JsonConvert.DeserializeObject <User>(userstr);
                List <FavLocation> favs    = await _manager.GetFavLocations(user.ID);

                List <int> userFavs = new List <int>();

                foreach (var fav in favs)
                {
                    userFavs.Add(fav.LocationId);
                }
                search.UserFavorites = userFavs;
                ViewData["User"]     = user.Name;
            }
            catch
            {
            }

            return(View(search));
        }
    }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            string    userSer = TempData.Peek("User").ToString();
            User      user    = JsonConvert.DeserializeObject <User>(userSer);
            Favorites favs    = new Favorites();

            favs.Locations = await _locContext.GetFavLocations(user.ID);

            favs.Retailers = await _retContext.GetFavRetailers(user.ID);

            return(View(favs));
        }