public JsonResult Get(string code)
        {
            var country = _dbContext.Country.Where(x => x.ShortName.Equals(code, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();

            if (country != null)
            {
                return(Json(CountryMaker.GetCountryData(country)));
            }

            return(Json(new object[] { new object() }));
        }
        public async Task <JsonResult> Get(int?page = null, int pageSize = 10, string searchString = "")
        {
            object countries = null;

            if (!string.IsNullOrEmpty(searchString))
            {
                countries = await PaginatedList <Country>
                            .CreateAsync(_dbContext.Country.Where(x => x.Name.ToUpper().StartsWith(searchString.ToUpper())), page ?? 1, pageSize);
            }
            else
            {
                countries = await PaginatedList <Country> .CreateAsync(_dbContext.Country, page ?? 1, pageSize);
            }
            return(Json(CountryMaker.GetCountriesData(countries as List <Country>, page ?? 1, pageSize)));
        }
Пример #3
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)));
        }
Пример #4
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
            });
        }