Beispiel #1
0
 /// <summary>
 /// ActionResult for the search page. Populates the page model with search results if artist or title parameters are passed.
 /// </summary>
 /// <param name="artist"></param>
 /// <param name="title"></param>
 /// <param name="min"></param>
 /// <returns></returns>
 public ActionResult Search(string artist = null, string track = null, bool min = false)
 {
     try
     {
         // Ensure that track and artist are not empty and are not searched for concurrently
         if ((!string.IsNullOrEmpty(artist) && !string.IsNullOrEmpty(track)) ||
             (string.IsNullOrEmpty(artist) && string.IsNullOrEmpty(track)))
         {
             return(View("/Views/Home/Index.cshtml", new SearchPageModel()));
         }
         else
         {
             // Build the search result model if an artist or track is specified
             var model = new SearchPageModel();
             ViewBag.Query = string.Empty;
             if (!string.IsNullOrEmpty(artist))
             {
                 model.ArtistResults = SpotifyController.SearchArtist(artist, min);
                 ViewBag.Query       = artist;
             }
             else if (!string.IsNullOrEmpty(track))
             {
                 model.TrackResults = SpotifyController.SearchTrack(track);
                 ViewBag.Query      = track;
             }
             return(View("/Views/Home/Search.cshtml", model));
         }
     }
     catch (Exception Ex)
     {
         // Write error to the console and return a 500 error to the browser
         Console.WriteLine("Exception Occurred: " + Ex.Message);
         return(new HttpStatusCodeResult((int)HttpStatusCode.InternalServerError));
     }
 }
Beispiel #2
0
        public async Task <SearchPageModel> BuildSearchPageModelAsync(Guid siteId, IList <Guid> forumIds, QueryOptions options)
        {
            var result = new SearchPageModel
            {
                Posts = await SearchPostModels(forumIds, options)
            };

            return(result);
        }
Beispiel #3
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e.Parameter is DiscordChannel channel)
     {
         ViewModel        = new SearchPageModel(channel);
         Root.DataContext = ViewModel;
     }
     else
     {
         ViewModel        = null;
         Root.DataContext = null;
     }
 }
Beispiel #4
0
        public SearchPage()
        {
            InitializeComponent();

            DataContext = new SearchPageModel();
        }
Beispiel #5
0
        public ActionResult Search(SearchPageModel data)
        {
            VerifyAPIKeys();
            TwitterService service = SetUpSearchService();

            //service.TraceEnabled = true;

            SearchOptions options = new SearchOptions();

            options.Lang  = "en";
            options.Count = Math.Max(data.searchData.myNumber, 0);
            /*Keep in mind that the search index has a 7-day limit. In other words, no tweets will be found for a date older than one week. https://dev.twitter.com/rest/reference/get/search/tweets*/

            //author
            var searchString = "from:" + (String.IsNullOrWhiteSpace(data.searchData.myUserName) ? "" : data.searchData.myUserName);

            //subject
            if (!String.IsNullOrWhiteSpace(data.searchData.myKeyword))
            {
                searchString += " " + data.searchData.myKeyword;
            }

            //location “37.781157,-122.398720”
            if (!String.IsNullOrEmpty(data.searchData.myLocation))
            {
                var    split = data.searchData.myLocation.Split(',');
                double lat   = 0;
                double lng   = 0;
                if (split.Length == 2 && double.TryParse(split[0], out lat) && double.TryParse(split[1], out lng))
                {
                    int radius = 5;
                    options.Geocode = new TwitterGeoLocationSearch(lat, lng, radius, TwitterGeoLocationSearch.RadiusType.Km);
                }
            }

            options.Q = searchString;
            options.IncludeEntities = true;
            options.Resulttype      = TwitterSearchResultType.Recent;
            options.Until           = DateTime.Now;
            options.IncludeEntities = false;
            options.SinceId         = 0;
            var err = "";
            TwitterSearchResult tweets;

            tweets = service.Search(options);

            if (tweets == null || tweets.Statuses.Count() == 0)
            {
                //no results broh, check if username is invalid if we can
                bool userProvided = !String.IsNullOrEmpty(data.searchData.myUserName);
                if (!String.IsNullOrEmpty(service?.Response?.Error?.Message))
                {
                    if (service.Response.Error.Message.ToLower().Contains("auth"))
                    {
                        err = service?.Response?.Error?.Message + " Please check web config API keys";
                    }
                    else
                    {
                        err = service?.Response?.Error?.Message;
                    }
                }
                else if (userProvided)
                {
                    //call here to avoid slowing down valid requests
                    var tweeter = service.GetUserProfileFor(new GetUserProfileForOptions()
                    {
                        ScreenName = data.searchData.myUserName
                    });
                    if (tweeter == null)
                    {
                        err = "User: "******" does not exist";
                    }
                }

                return(View(new SearchPageModel()
                {
                    searchData = data.searchData, errorMessage = err
                }));
            }

            var simplerResults = new List <TweetInfo>();

            foreach (var t in tweets.Statuses)
            {
                simplerResults.Add(new Models.TweetInfo
                {
                    Author        = t.Author.ScreenName
                    , timeStamp   = t.CreatedDate.ToLocalTime() //display time in server time, not UTC
                    , TweetString = t.Text
                });
            }

            return(View(new SearchPageModel()
            {
                searchData = data.searchData, tweets = simplerResults
            }));
        }
 public SearchPageViewModel(SearchPageModel currentPage) : base(currentPage)
 {
     _currentPage = currentPage;
 }