public async Task <ActionResult> Countries(int page, int rows, string sidx, string sord, int?countryId = null)
        {
            JsonResult result = null;

            jqGridResponse <CountryDTO> jqgridResponse = null;

            try
            {
                CountryDTOList     countryList = null;
                IList <CountryDTO> countries   = null;

                if (countryId.HasValue)
                {
                    // Find the page on which the countryId is located based on the sorting
                    countryList = await AirportBusinessService.GetCountries(sidx, sord);

                    int index = 0;
                    for (index = 0; index < countryList.Countries.Count; index++)
                    {
                        if (countryList.Countries[index].CountryId == countryId)
                        {
                            break;
                        }
                    }

                    int offset = 0;

                    if (index < countryList.Countries.Count)
                    {
                        page   = index / rows + 1;
                        offset = (page - 1) * rows;
                    }

                    countries = countryList.Countries.Skip(offset).Take(rows).ToList();
                }
                else
                {
                    int offset = (page - 1) * rows;
                    countryList = await AirportBusinessService.GetCountries(sidx, sord, offset, rows);

                    countries = countryList.Countries;
                }

                int totalPages = (countryList.TotalRecords + rows - 1) / rows;
                jqgridResponse = new jqGridResponse <CountryDTO>(page, countryList.TotalRecords, totalPages, countries, countryId);
            }
            catch (Exception exception)
            {
                jqgridResponse = new jqGridResponse <CountryDTO>(0, 0, 0, new List <CountryDTO>(), exception.Message);
            }

            result = Json(jqgridResponse);
            return(result);
        }
Example #2
0
        public async Task <CountryDTOList> GetCountries(string orderBy = "", string orderDirection = "ASC", int?offset = null, int?take = null)
        {
            var countryList = await DataServices.GetCountries(CountryDTO.Includes, orderBy, orderDirection, offset, take);

            CountryDTOList list = new CountryDTOList
            {
                TotalRecords = countryList.TotalRecords,
                Countries    = countryList.Countries.Select(c => new CountryDTO(c)).ToList()
            };

            return(list);
        }