private DataTable GetSearchResult(Resource resource, ICollection <PropertyValuePair> searchCriteria) { int totalRecords = 0; int totalParsedRecords = GridViewMatchingRecord.PageSize * pager.PageIndex; int index = resource.ToString().LastIndexOf(_CharDot); int minimumPercentageMatchExpected = Convert.ToInt32((MinPerMatchTextBox.Text)); IEnumerable <SimilarRecord> records = null; AuthenticatedToken userToken = (AuthenticatedToken)Session[Constants.AuthenticationTokenKey]; DataTable similarRecordsTable = new DataTable(); similarRecordsTable.Columns.Add(_id); similarRecordsTable.Columns.Add(_title); similarRecordsTable.Columns.Add(_percentageMatch); using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext())) { records = dataAccess.SearchSimilarResource(resource.ToString().Substring(index + 1), searchCriteria, userToken, totalParsedRecords, out totalRecords, GridViewMatchingRecord.PageSize) .Where(tuple => tuple.PercentageMatch > minimumPercentageMatchExpected); foreach (SimilarRecord record in records) { DataRow row = similarRecordsTable.NewRow(); row[_id] = record.MatchingResource.Id; row[_title] = HttpUtility.HtmlEncode(record.MatchingResource.Title); row[_percentageMatch] = record.PercentageMatch; similarRecordsTable.Rows.Add(row); } } if (GridViewMatchingRecord.PageSize > 0 && totalRecords > 0) { if (totalRecords > GridViewMatchingRecord.PageSize) { pager.TotalPages = Convert.ToInt32(Math.Ceiling((double)totalRecords / GridViewMatchingRecord.PageSize)); } else { pager.PageIndex = 0; pager.TotalPages = 1; } } else { pager.PageIndex = 0; pager.TotalPages = 0; } return(similarRecordsTable); }