예제 #1
0
        /// <summary>
        ///     Reads venues from FourSquare API and store searchQuery in DB
        /// </summary>
        /// <param name="searchQuery">searchQuery used by user</param>
        /// <returns>model with first 10 venues from FourSquare API</returns>
        public SearchModel GetVenuesModelForSearchQuery(string searchQuery)
        {
            if (string.IsNullOrEmpty(searchQuery))
            {
                return new SearchModel();
            }

            var parameters = this.GetParametersForSearchQuery(searchQuery);
            var query = this._queryService.ExistsSearchQuery(searchQuery)
                ? this._queryService.UpdateSearchQuery(searchQuery)
                : this._queryService.CreateAndSaveSearchQuery(searchQuery);

            var searchModel = new SearchModel
            {
                SearchQuery = searchQuery,
                SearchQueryCount = query.Count,
                VenuesTotalCount = this.GetVenuesCount(parameters),
                Venues = this._sharpSquare
                    .SearchVenues(parameters)
                    .Take(10)
                    .Select(venue => new VenueModel
                    {
                        Id = venue.id,
                        Name = venue.name,
                        CheckinCount = venue.stats.checkinsCount,
                        NowHere = venue.hereNow.count
                    }).ToList()
            };


            return searchModel;
        }
예제 #2
0
        public ActionResult SearchVenues(SearchModel model)
        {
            if (string.IsNullOrEmpty(model.SearchQuery) || string.IsNullOrWhiteSpace(model.SearchQuery))
            {
                model.SearchQuery = null;
                model.Venues.Clear();
                model.VenuesTotalCount = 0;
                return this.PartialView("_VenuesPartialView", model);
            }

            model = this._service.GetVenuesModelForSearchQuery(model.SearchQuery);
            return this.PartialView("_VenuesPartialView", model);
        }