Example #1
0
        public IActionResult Favorites(string sortOrder, string currentFilter,
                                       string searchString,
                                       int?page)
        {
            int pageSize          = 10;
            var favoriteCountries = GetAllFavorites();
            List <CountryViewModel> paginatedCountryDataList = new List <CountryViewModel>();
            var paginatedCountryList = PaginatedList <Country> .CreateNonAsync(favoriteCountries, page ?? 1, pageSize);

            Parallel.ForEach((List <Country>)paginatedCountryList, (country) =>
            {
                paginatedCountryDataList.Add(CountryMaker.PopulateFullCountryData(country, true));
            });
            return(View(new PaginatedList <CountryViewModel>(paginatedCountryDataList, favoriteCountries.Count(), page ?? 1, pageSize)));
        }
Example #2
0
        public JsonResult GetCountryData(string countryName, int pageNumber)
        {
            if (string.IsNullOrEmpty(countryName))
            {
                return(Json(null));
            }
            var country = _dbContext.Country.Where(x => x.Name.Equals(countryName)).SingleOrDefault();

            if (country == null)
            {
                return(Json(null));
            }

            var  userId     = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            bool isFavorite = _dbContext.Favorites.Any(x => x.UserId.Equals(userId) && x.CountryId.Equals(country.CountryId));

            CountryViewModel countryData = CountryMaker.PopulateFullCountryData(country, isFavorite);

            return(Json(countryData));
        }
        public async Task <object> Get(int?page = null, int pageSize = 10)
        {
            List <object> countriesList = new List <object>();
            var           userId        = _caller.Claims.Single(c => c.Type == "id");
            object        countries     = null;
            var           favorites     = _dbContext.Favorites.Where(c => c.UserId == userId.Value);


            countries = await PaginatedList <Favorites> .CreateAsync(favorites, page ?? 1, pageSize);

            foreach (var favorite in (List <Favorites>)countries)
            {
                var country = _dbContext.Country.Where(x => x.CountryId == favorite.CountryId).FirstOrDefault();
                countriesList.Add(CountryMaker.PopulateFullCountryData(country, true));
            }
            return(new
            {
                countries = countriesList.ToList(),
                page = page,
                pageSize = pageSize
            });
        }