public async Task <ActionResult> SearchFunctions(FunctionSearchQuery fsq)
        {
            if (ModelState.IsValid)
            {
                var query = from sp in FaToolDbEntities.GetProteinSearchValues(ProteinSearchOption.ProteinName, fsq.OrganismId)
                            join fp in FaToolDbEntities.GetProteinSearchValues(ProteinSearchOption.Function, fsq.OrganismId) on sp.ProteinID equals fp.ProteinID
                            where sp.Value == fsq.SearchName && fp.OntologyID == fsq.OntologyId
                            select new { id = fp.TermID, name = fp.TermName };

                var results = await query.ToArrayAsync();

                return(Json(results, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }
        }
        private async Task <ProteinSearchViewModel> Search(ProteinSearchQuery psq, int pageIndex)
        {
            var model = await CreateModel(psq, pageIndex);

            var query = FaToolDbEntities
                        .GetProteinSearchValues(psq.SearchOption, psq.SourceOrganismID)
                        .Where(pv => pv.Value.Contains(psq.SearchValue));

            int numResults = await query.CountAsync();

            if (numResults == 0)
            {
                model.StatusDescription = "Query does not return any results.";
            }
            else
            {
                int numPages = DataPaging.CalculatePageCount(numResults);
                pageIndex = DataPaging.FixPageIndex(numPages, pageIndex);
                int skip = DataPaging.CalculateSkipCount(numResults, pageIndex);

                var proteinValues = await query
                                    .OrderBy(x => x.Value)
                                    .ThenBy(x => x.TermName)
                                    .ThenBy(x => x.ProteinName)
                                    .Skip(skip)
                                    .Take(DataPaging.PageSize)
                                    .ToArrayAsync();

                model.Results = proteinValues
                                .Select(CreateItem)
                                .ToArray();

                model.StatusDescription = CreateDescription(numResults, numPages, pageIndex);
            }

            return(model);
        }