private async Task <ActionResult> SearchGroups(GroupSearchViewModel model) { if (model.SearchType == eSearchType.Group && model.GroupSearchModel.Text.IsNullOrEmpty()) { return(RedirectToSearchPage(model)); } if (model.GroupSearchModel.AutoSuggestValueAsInt.HasValue) { return(RedirectToDetailPage(model.GroupSearchModel.AutoSuggestValueAsInt.Value)); } else { model.SearchQueryString = Request.QueryString.ToString(); var text = model.GroupSearchModel.Text.Clean(); model.GroupTypes = (await _lookupService.GroupTypesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList(); model.GroupStatuses = (await _lookupService.GroupStatusesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList(); ApiPagedResult <SearchGroupDocument> results = null; if (text != null) { results = await _groupReadService.SearchByIdsAsync(text, text.ToInteger(), text, text.ToInteger(), User); } if (results != null && results.Count > 0) { model.Results.Add(results.Items[0]); model.Count = 1; } else { var payload = CreateSearchPayload(model); results = await _groupReadService.SearchAsync(payload, User); model.Results = results.Items; if (model.StartIndex == 0) { model.Count = results.Count; } } if (model.Count == 1) { return(RedirectToDetailPage(model.Results.Single().GroupUId)); } if (model.Count == 0) { return(RedirectToSearchPage(model)); } return(View("GroupResults", model)); } }