public CountryGridVM GetCountries(DataTableModel table) { CountryGridVM result = new CountryGridVM(); using (CountryDbContext context = new CountryDbContext()) { //5. büyük nüfusa sahip ülke alınıyor IQueryable <Country> countryQuery = context.CountryList.Include("Region"); if (!string.IsNullOrEmpty(table.sSearch)) { string searchText = table.sSearch.ToLower(); countryQuery = countryQuery.Where(c => c.CapitalCity.Contains(searchText) || c.Name.Contains(searchText) || c.FullName.Contains(searchText) || c.Code.Contains(searchText) || c.Region.Name.Contains(searchText)); } result.TotalCount = countryQuery.Count(); if (!string.IsNullOrEmpty(table.SingleSortingColumn)) { countryQuery = countryQuery.OrderByField(table.SingleSortingColumn, table.SingleSortDirection); } else { countryQuery = countryQuery.OrderByDescending(m => m.Population); } countryQuery = countryQuery.Skip(table.iDisplayStart).Take(table.iDisplayLength); result.CountryList = countryQuery.ToList(); if (AppConfig.RenderFlagOnGrid) { result.CountryList.ForEach(c => c.Base64FlagData = Convert.ToBase64String(File.ReadAllBytes(AppConfig.FlagPath + string.Format(c.Flag, AppConfig.FlagResolution)))); } } return(result); }
public ActionResult GetCountries(DataTableModel table) { Util.TableSortByRequest(table, table.iSortCol_0, table.sSortDir_0); CountryGridVM response = DatabaseContext.CountryRepository.GetCountryList(table); return(Json(new { sEcho = table.sEcho, iTotalRecords = table.iDisplayLength, iTotalDisplayRecords = response.TotalCount, aaData = response.CountryList }, JsonRequestBehavior.AllowGet)); }
public CountryGridVM GetCountryList(DataTableModel model) { WebClient client = new WebClient(); client.Headers["Accept"] = "application/json"; string url = string.Format(AppConfig.ApiUrl + base.GetApiController() + "/GetCountries?iColumns={0}&iDisplayLength={1}&iDisplayStart={2}&iSortingCols={3}&sColumns={4}" + "&sEcho={5}&SingleSortDirection={6}&SingleSortingColumn={7}&sSearch={8}", model.iColumns, model.iDisplayLength, model.iDisplayStart, model.iSortingCols, model.sColumns, model.sEcho, model.SingleSortDirection, model.SingleSortingColumn, model.sSearch); string returnedString = client.DownloadString(new Uri(url)); CountryGridVM vm = JsonConvert.DeserializeObject <CountryGridVM>(returnedString); return(vm); }