public IActionResult Search() { try { string term = HttpContext.Request.Query["term"].ToString(); var names = _artist.GetAll() .Where(p => p.ArtistName.ToUpper().Contains(term.ToUpper())) .Select(p => p.ArtistName).ToList(); return(Ok(names)); } catch { return(BadRequest()); } }
public async Task <IActionResult> Index(int artistId, MainIndexModel srch) { var url = "https://localhost:44334/api/SearchRest/searchArtistsByGenres?"; // put in appSettings //var url = "https://wikivox.azurewebsites.net/api/SearchRest/searchArtistsByGenres?"; // put in appSettings var terms = string.Empty; if (srch.GenreListing == null) { // default genre search terms = "term=1"; } else { //loop thru list and obtain search terms foreach (var g in srch.GenreListing) { if (g.isMarked) { if (terms == string.Empty) { terms += "term=" + g.Id; } else { terms += "&term=" + g.Id; } } } } List <Artist> artistModel = new List <Artist>(); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(url + terms)) { string apiResponse = await response.Content.ReadAsStringAsync(); artistModel = JsonConvert.DeserializeObject <List <Artist> >(apiResponse); } } // by default, load one artist in object for launch page Random rnd = new Random(); int artistNum = _artist.GetAll().Count(); //var x = x - 1; int defaultArtistId = rnd.Next(1, artistNum - 1); var artistInfoModel = _artist.Get(defaultArtistId); // if an artist has been selected, gather details to display if (artistId != 0) { artistInfoModel = _artist.Get(artistId); } var genreModel = _genre.GetAll(); var artistGenreModel = _artistGenre.GetAll(); // genre list var genres = genreModel.Select (g => new GenreListingModel { Id = g.Id, Name = g.Name } ).ToList(); // artist list var artists = artistModel.Select (a => new ArtistListingModel { Id = a.Id, ArtistName = a.ArtistName } ).ToList(); var artistGenres = artistGenreModel.Select (r => new ArtistGenreModel { Id = r.Id, Artist = r.Artist, Genre = r.Genre } ).ToList(); var artistInfo = new ArtistListingModel { Id = artistInfoModel.Id, ArtistName = artistInfoModel.ArtistName, Bio = artistInfoModel.Bio, YrFormed = artistInfoModel.YrFormed, YrEnded = artistInfoModel.YrEnded, isActive = artistInfoModel.isActive, HomeCountry = artistInfoModel.HomeCountry, HomeTown = artistInfoModel.HomeTown, PrimaryImage = _image.GetPrimaryImageByEntity(2, artistInfoModel.Id, 1) }; var model = new MainIndexModel { GenreListing = genres, ArtistListing = artists, ArtistGenre = artistGenres, ArtistInfo = artistInfo }; return(View(model)); }
public ActionResult <IEnumerable <Artist> > Get() { return(_artist.GetAll().ToList()); }