public IHttpActionResult GetSearchAutoCompleteData([FromUri] GetSearchRequest getSearchRequest) { var responses = new Responses(); try { SpellingAutoCorrect spellingAutoCorrect = new SpellingAutoCorrect(); string correctSearchText = ""; foreach (var item in getSearchRequest.SearchText.Split(' ')) { correctSearchText += " " + (new Regex("^[a-zA-Z0-9 ]*$").IsMatch(item) ? spellingAutoCorrect.Correct(item) : Regex.Replace(item, @"[^0-9a-zA-Z]+", "")); } var search = new Search() { SearchText = correctSearchText }; var searches = iSearch.GetSearchAutoCompleteData(search); var searchList = new List <GetSearchResponse>(); foreach (var searchDetail in searches) { searchList.Add(new GetSearchResponse() { SearchContent = searchDetail.SearchContent }); } responses.Status = Utility.SUCCESS_STATUS_RESPONSE; responses.Description = "Search AutoComplete data retrieved successfully"; responses.Response = searchList; } catch (Exception ex) { responses.Status = Utility.ERROR_STATUS_RESPONSE; responses.Description = "Error while retrieving Search AutoComplete data."; Utility.WriteLog("GetSearchAutoCompleteData", null, "Error while retrieving Search AutoComplete data. (UtilityController)", ex.ToString()); } return(Ok(responses)); }
public IHttpActionResult GetSearchData([FromUri] GetSearchRequest getSearchRequest) { var responses = new Responses(); try { SpellingAutoCorrect spellingAutoCorrect = new SpellingAutoCorrect(); string correctSearchText = ""; foreach (var item in getSearchRequest.SearchText.Split(' ')) { correctSearchText += " " + (new Regex("^[a-zA-Z0-9 ]*$").IsMatch(item) ? spellingAutoCorrect.Correct(item) : Regex.Replace(item, @"[^0-9a-zA-Z]+", "")); } var search = new Search() { CategoryId = getSearchRequest.CategoryId, SearchText = correctSearchText, PageNumber = getSearchRequest.PageNumber, PageSize = Convert.ToInt32(getSearchRequest.PageSize), IsPagingRequired = (getSearchRequest.PageNumber != null) ? true : false, OrderBy = getSearchRequest.OrderBy, OrderByDirection = getSearchRequest.OrderByDirection }; var searches = iSearch.GetSearchData(search); var searchList = new List <GetSearchResponse>(); foreach (var searchDetail in searches) { searchList.Add(new GetSearchResponse() { CategoryId = searchDetail.CategoryId, Number = searchDetail.Number, Name = searchDetail.Name, Content = searchDetail.Content, PDF = searchDetail.PDF, Excel = searchDetail.Excel, Word = searchDetail.Word, TotalPageCount = searchDetail.TotalPageCount, TotalRecord = searchDetail.TotalRecord }); } responses.Status = Utility.SUCCESS_STATUS_RESPONSE; responses.Description = "Search data retrieved successfully"; responses.Response = searchList; } catch (Exception ex) { responses.Status = Utility.ERROR_STATUS_RESPONSE; responses.Description = "Error while retrieving Search data."; Utility.WriteLog("GetSearchData", null, "Error while retrieving Search data. (UtilityController)", ex.ToString()); } return(Ok(responses)); }