Пример #1
0
        public async Task <IBestBetDisplay[]> Get(string collection, string language, string term)
        {
            if (String.IsNullOrWhiteSpace(collection))
            {
                throw new APIErrorException(400, "You must supply a collection, language and search term");
            }

            if (collection.ToLower() != "preview" && collection.ToLower() != "live")
            {
                throw new APIErrorException(404, "Unsupported collection. Please try 'live'");
            }

            if (String.IsNullOrWhiteSpace(language))
            {
                throw new APIErrorException(400, "You must supply a language and search term");
            }

            if (language.ToLower() != "en" && language.ToLower() != "es")
            {
                throw new APIErrorException(404, "Unsupported Language. Please try either 'en' or 'es'");
            }

            if (String.IsNullOrWhiteSpace(term))
            {
                throw new APIErrorException(400, "You must supply a search term");
            }

            // Term comes from from a catch-all parameter, so make sure it's been decoded.
            term = WebUtility.UrlDecode(term);

            // Step 1. Remove Punctuation
            string cleanedTerm = CleanTerm(term);

            string[] categoryIDs = await _matchService.GetMatches(collection.ToLower(), language.ToLower(), cleanedTerm);

            List <IBestBetDisplay> displayItems = new List <IBestBetDisplay>();

            var categoryTasks = from categoryID in categoryIDs
                                select _displayService.GetBestBetForDisplay(collection.ToLower(), categoryID);

            var categoryItems = await Task.WhenAll(categoryTasks);

            foreach (IBestBetDisplay item in categoryItems)
            {
                displayItems.Add(new BestBetAPIGetResult()
                {
                    ID     = item.ID,
                    Name   = item.Name,
                    Weight = item.Weight,
                    HTML   = item.HTML
                });
            }

            return(displayItems.ToArray());
        }
Пример #2
0
        public IBestBetDisplay[] Get(string language, string term)
        {
            if (String.IsNullOrWhiteSpace(language))
            {
                throw new APIErrorException(400, "You must supply a language and search term");
            }

            if (language.ToLower() != "en" && language.ToLower() != "es")
            {
                throw new APIErrorException(404, "Unsupported Language. Please try either 'en' or 'es'");
            }

            if (String.IsNullOrWhiteSpace(term))
            {
                throw new APIErrorException(400, "You must supply a search term");
            }

            // Step 1. Remove Punctuation
            string cleanedTerm = CleanTerm(term);

            string[] categoryIDs = _matchService.GetMatches(language.ToLower(), cleanedTerm);

            List <IBestBetDisplay> displayItems = new List <IBestBetDisplay>();

            //Now get categories for ID.
            foreach (string categoryID in categoryIDs)
            {
                IBestBetDisplay item = _displayService.GetBestBetForDisplay(categoryID);
                displayItems.Add(new BestBetAPIGetResult()
                {
                    ID     = item.ID,
                    Name   = item.Name,
                    Weight = item.Weight,
                    HTML   = item.HTML
                });
            }

            return(displayItems.ToArray());
        }