public async Task <IActionResult> Moods() { var appUser = await _userManager.GetUserAsync(User); var user = await _jukeboxRepository.GetUserAsync(appUser.Id); var moods = await _jukeboxRepository.GetAllMoodsAsync(); var model = new MoodsViewModel(StatusMessage, moods, user); return(View(model)); }
public async Task <IActionResult> Jukebox(JukeboxViewModel model) { if (!ModelState.IsValid) { var allTempPlaylists = await _jukeboxRepository.GetAllPlaylistsAsync(); var tempModel = new JukeboxViewModel(allTempPlaylists); return(View(tempModel)); } var allPlaylists = await _jukeboxRepository.GetAllPlaylistsAsync(); String[] searchedMoods = model.Search.Split(' '); var allMoods = await _jukeboxRepository.GetAllMoodsAsync(); var foundedMoods = new List <Mood>(); foreach (var search in searchedMoods) { if (allMoods.Any(mood => mood.Value.ToLower().Equals(search.ToLower()))) { foundedMoods.Add(allMoods.First(mood => mood.Value.ToLower().Equals(search.ToLower()))); } } var filteredMoods = foundedMoods.Where(mood => mood.Playlists != null).ToList(); var filteredPlaylists = new List <Playlist>(); foreach (var mood in filteredMoods) { foreach (var playlist in mood.Playlists) { if (!filteredPlaylists.Contains(playlist)) { filteredPlaylists.Add(playlist); } } } var newModel = new JukeboxViewModel(allPlaylists, filteredPlaylists, model.Search) { Moods = foundedMoods }; return(View(newModel)); }