Пример #1
0
        /// <summary>
        /// Generates new suggestions through Google API if current ones are exchausted
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private async Task GenerateNewSuggestions(string type)
        {
            var keywords = await Fetch(type);

            if (keywords.Count == 0)
            {
                throw new ArgumentException("Not enough keywords to create a suggestion list");
            }

            // This will give only 1, so the suggestions will be only from 1 city
            List <GooglePlaceObject> total = new List <GooglePlaceObject>();


            // Generate for cities
            for (int i = 0; i < TotalCitiesSuggestions; i++)
            {
                if (keywords.Count == 0)
                {
                    break;
                }

                var main = GetRandomKeyword(keywords);

                // Exclude this city from future requests
                keywords = keywords.Where(x => x.KeywordAddress.City != main.KeywordAddress.City).ToList();

                total.AddRange(await googleService.GetNearbyPlaces(main));
            }

            await WriteSuggestionsFile(total, userId);
        }
        public async Task <GooglePlaceObject[]> GetGuestSuggestions(UserKeywords keywords)
        {
            var result = await googleService.GetNearbyPlaces(keywords);

            if (result.Count > 8)
            {
                return(result.Take(8).ToArray());
            }

            return(result.ToArray());
        }