//for search... //var query = from p in db.purchases // join pi in db.purchaseitems on p.PurchaseID equals pi.purchase.purchaseID // where blah blah blah // select pi.PurchaseItemSong.SongID // GET: Artists public ActionResult Index(string SearchString) { var query = from a in db.Artists select a; //create a view bag to store the number of selected customers ViewBag.TotalArtistCount = db.Artists.Count(); //create a list of selected customers List <Artist> SelectedArtists = new List <Artist>(); // create count of selected customers ViewBag.SelectedArtistCount = db.Artists.Count(); if (SearchString == null || SearchString == "") //didnt select anything { SelectedArtists = query.ToList(); } else //something was picked { //linq to display searched name SelectedArtists = query.Where(c => c.ArtistName.Contains(SearchString)).ToList(); int SelectedArtistCount = SelectedArtists.Count(); // create count of selected artists ViewBag.SelectedArtistCount = SelectedArtists.Count(); //order by artists name then average rating //TODO: Order by avg rating when we figure that out SelectedArtists.OrderBy(c => c.ArtistName); //return view with selected artists //return View(SelectedArtists); } //Add average rating to index List <ArtistIndexViewModel> ArtistDisplay = new List <ArtistIndexViewModel>(); foreach (Artist a in SelectedArtists) { ArtistIndexViewModel AVM = new ArtistIndexViewModel(); AVM.Artist = a; AVM.ArtistRating = getAverageRating(a.ArtistID).ToString("0.0"); ArtistDisplay.Add(AVM); } return(View(ArtistDisplay)); }
// Display an artist profile public async Task <IActionResult> Index(string userName) { if (string.IsNullOrEmpty(userName)) { return(NotFound()); } Artist artist = await _userManager.FindByNameAsync(userName); if (artist == null) { return(NotFound()); } // Privacy settings if (_signInManager.IsSignedIn(User)) { Artist user = await _userManager.GetUserAsync(User); if (user != null && (!artist.IsPubliclyVisible && user != artist)) { return(NotFound()); } } else { if (!artist.IsPubliclyVisible) { return(NotFound()); } } ArtistIndexViewModel viewModel = new ArtistIndexViewModel { Artist = artist }; // Check if the viewer is following the artist if (_signInManager.IsSignedIn(User)) { Artist user = await _userManager.GetUserAsync(User); Artist toFollow = await _userManager.FindByNameAsync(userName); FollowRelation followRelation = await _context.FollowRelations.FirstOrDefaultAsync(x => x.FromArtistId == user.Id && x.ToArtistId == toFollow.Id); ViewData["isFollowing"] = followRelation != null ? true : false; } return(View(viewModel)); }
public ActionResult Index() { Artist artist = GetCurrentArtist(); List <ArtistTask> mailingTasks = GetMailingListArtistTask(artist); List <ArtistTask> concertTasks = GetConcertArtistTasks(artist); List <ArtistTask> allTasks = new List <ArtistTask>(); allTasks.AddRange(mailingTasks); allTasks.AddRange(concertTasks); ArtistIndexViewModel artistInfo = new ArtistIndexViewModel() { RecommendedTasks = allTasks }; return(View(artistInfo)); }
public async Task <IActionResult> Index([FromQuery] int page = 0, PublishStatus?status = null) { ArtistIndexViewModel model = new ArtistIndexViewModel(); page = Math.Max(page, 0); PublishStatus flags = PublishStatus.PUBLISHED | PublishStatus.UNPUBLISHED; if (status.HasValue) { flags = status.Value; } var result = await _artistRepo.ListAsync(page, _pageSize, flags); model.PageIndex = result.PageIndex; model.PageSize = result.PageSize; model.TotalPages = (int)Math.Ceiling(((double)result.TotalItems / (double)result.PageSize)); ArtistViewModelMapper mapper = new ArtistViewModelMapper(); model.Items.AddRange(result.Items.Select(i => mapper.Map(i))); return(View(model)); }
//Detailed search results public ActionResult ArtistSearchResults(string ArtistSearchString, string RatingString, SortOrder SelectedBounds, int[] SelectedGenre) { var query = from a in db.Artists select a; if (ArtistSearchString == null || ArtistSearchString == "") //they didn't select anything { ViewBag.ArtistSearchString = "Search String was null"; } else //they picked something up { ViewBag.ArtistSearchString = "The search string is" + ArtistSearchString; query = query.Where(a => a.ArtistName.Contains(ArtistSearchString)); } if (SelectedGenre == null) //nothing was selected { ViewBag.SelectedGenre = "No genres were selected"; } else { String strSelectedGenre = "The selected genre(s) is/are: "; //get list of genres ViewBag.AllGenres = GetAllGenres(); foreach (int GenreID in SelectedGenre) { query = query.Where(s => s.ArtistGenre.Any(g => g.GenreID == GenreID)); } ViewBag.SelectedGenre = strSelectedGenre; } if (RatingString != "") //make sure string is a valid number { Decimal decRating; try { decRating = Convert.ToDecimal(RatingString); } catch // this code will disolay when something is wrong { //Add a message for the viewbag ViewBag.Message = RatingString + "is not valid number. Please try again"; //send user back to homepage return(View("ArtistDetailedSearch")); } List <ArtistIndexViewModel> ArtistsDisplay_descend = new List <ArtistIndexViewModel>(); List <ArtistIndexViewModel> ArtistsDisplay_ascend = new List <ArtistIndexViewModel>(); foreach (Artist a in query) { Decimal d = getAverageRating(a.ArtistID); if (d >= decRating) { ArtistIndexViewModel ab = new ArtistIndexViewModel(); ab.Artist = a; ab.ArtistRating = d.ToString("0.0"); ArtistsDisplay_ascend.Add(ab); } else { ArtistIndexViewModel ab = new ArtistIndexViewModel(); ab.Artist = a; ab.ArtistRating = d.ToString("0.0"); ArtistsDisplay_descend.Add(ab); } } IEnumerable <ArtistIndexViewModel> new_list_artists = ArtistsDisplay_ascend; IEnumerable <ArtistIndexViewModel> new_list_artists_lt = ArtistsDisplay_descend; if (SelectedBounds == SortOrder.ascending) { ViewBag.SelectedSortOrder = "The records should be sorted in ascending order"; return(View("Index", new_list_artists)); } else { ViewBag.SelecredSortOrder = "The records should be sored in descending order"; return(View("Index", new_list_artists_lt)); } } List <ArtistIndexViewModel> ArtistsList = new List <ArtistIndexViewModel>(); foreach (Artist a in query) { Decimal d = getAverageRating(a.ArtistID); ArtistIndexViewModel ab = new ArtistIndexViewModel(); ab.Artist = a; ab.ArtistRating = d.ToString("0.0"); ArtistsList.Add(ab); } return(View("Index", ArtistsList)); }