Example #1
0
        /// <summary>
        /// Method used to query database for English language results. This will return the
        /// data in XML format. There is no way to create an additional WebGet so that we
        /// can return the same data in JSON format.
        /// </summary>
        /// <param name="language">The language needed to do the lookup</param>
        /// <param name="criteria">The partial text used to query the database</param>
        /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param>
        /// <param name="contains">Indicator on whether the text is to be search from the beginning of the text or anywhere in the string</param>
        /// <returns>Returns the search results</returns>
        private AutoSuggestSearchServiceCollection Search(string language, string criteria, int maxRows, bool contains)
        {
            // create the collection variable
            AutoSuggestSearchServiceCollection sc = new AutoSuggestSearchServiceCollection();

            try
            {
                // language passed to an enum
                DisplayLanguage displayLanguage =
                    (DisplayLanguage)Enum.Parse(typeof(DisplayLanguage), language);

                // Call the database query
                AutoSuggestSearchCollection dc =
                    AutoSuggestSearchManager.Search(language, criteria, maxRows, contains);

                // Use Linq to extract the data from the business layer and create
                // the service data objects
                // TermID is 0 always , that value is not part of the result received from the call to
                // Stroed procedure.But can be used in the future for other purposes.
                var collection = dc.ConvertAll(entry => new AutoSuggestSearchServiceItem(
                                                   entry.TermID,
                                                   entry.TermName,
                                                   string.Empty
                                                   ));

                sc.AddRange(collection);
            }
            catch (Exception ex)
            {
                // Log the error that occured
                CancerGovError.LogError("AutoSuggestSearch", 2, ex);
            }

            return(sc);
        }
Example #2
0
        /// <summary>
        /// This methods filters the information passed to it in order to refine the query
        /// that will be called in the database layer.
        /// </summary>
        /// <param name="language">enumeration indicating language</param>
        /// <param name="criteria">The partial text used to query the database</param>
        /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param>
        /// <param name="contains">indicator as to whether the text is to be searched starting from the beginning or anywhere
        ///                        in the string</param>
        /// <returns>Returns the search results</returns>
        public static AutoSuggestSearchCollection Search(string language, string criteria, int maxRows, bool contains)
        {
            AutoSuggestSearchCollection dc = new AutoSuggestSearchCollection();

            // Find out how we should search for the string
            if (Strings.Clean(criteria) != null)
            {
                // input criteria cleaup
                // 1. replace any ',' or ';' with space
                // 2. Trim whitespace.
                criteria = criteria.Trim();
                criteria = criteria.Replace(",", " ");
                criteria = criteria.Replace(";", " ");

                // Find out the field we need to get to build our list
                string fieldName = "TermName";
                if (language == "Spanish")
                {
                    fieldName = language.ToString() + fieldName;
                }

                try
                {
                    // Call the database layer and get data
                    DataTable dt = AutoSuggestSearchQuery.Search(
                        language.ToString(),
                        criteria,
                        maxRows);

                    // use Linq to move information from the dataTable
                    // into the AutoSuggestSearchCollection
                    dc.AddRange(
                        from entry in dt.AsEnumerable()
                        select GetEntryFromDR(entry)
                        );
                }
                catch (Exception ex)
                {
                    CancerGovError.LogError("TermDictionatyManager", 2, ex);
                    throw ex;
                }
            }

            return(dc);
        }