public async Task <IActionResult> Index() { MusicIndexViewModel model = new MusicIndexViewModel(); var user = await _userManager.GetUserAsync(HttpContext.User); model.Music = new List <MusicIndexListViewModel>(); var musicFromDb = await _userDbService.GetMusicListForUserAsync(user.Id); foreach (var music in musicFromDb) { model.Music.Add(new MusicIndexListViewModel { Id = music.Id, Title = music.Title, Type = "Music" }); } return(View(model)); }
public async Task <IActionResult> Index(bool alreadyAdded = false) { string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var songs = await _songService.GetSongs(); var bands = await _applicationDbContext.Bands.ToListAsync(); var albums = await _applicationDbContext.Albums.ToListAsync(); List <SelectListItem> bandSelectList, albumSelectList; ToSelectList(bands, albums, out bandSelectList, out albumSelectList); var userPlaylists = await GetUserPlayLists(userId); var songModels = new List <SongIndexViewModel>(); foreach (var song in songs) { if (song.Hidden) { songModels.Add(new SongIndexViewModel { Hidden = true, Id = song.Id, }); } else { var model = new SongIndexViewModel { Id = song.Id, Hidden = false, SongTitle = song.Title, Duration = song.Duration, }; if (song.Album != null) { model.AlbumId = song.AlbumId; model.AlbumTitle = song.Album.Title; model.ReleaseDate = song.Album.ReleaseDate; if (song.Album.Band != null) { model.BandName = song.Album.Band.Name; } } songModels.Add(model); } } var vm = new MusicIndexViewModel { Songs = songModels, PlayLists = userPlaylists, BandNames = bandSelectList, AlbumTitles = albumSelectList, AlreadyAdded = alreadyAdded }; return(View(vm)); }
public MusicIndexView(MusicIndexViewModel viewModel) { InitializeComponent(); this.DataContext = viewModel; }
public async Task <IActionResult> Index(SongFilterViewModel vm) { var selectedBand = (await _applicationDbContext.Bands .FirstOrDefaultAsync(band => band.Id == vm.SelectedBand))?.Name ?? ""; var selectedAlbum = (await _applicationDbContext.Albums .FirstOrDefaultAsync(album => album.Id == vm.SelectedAlbum))?.Title ?? ""; if (vm.SelectedAlbum == 0 && vm.SelectedBand == 0) { return(RedirectToAction("Index")); } string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var bands = await _applicationDbContext.Bands.ToListAsync(); var albums = await _applicationDbContext.Albums.ToListAsync(); List <SelectListItem> bandSelectList, albumSelectList; ToSelectList(bands, albums, out bandSelectList, out albumSelectList); var songs = await _songService.GetSongs(); IEnumerable <Song> albumsFiltered = vm.SelectedAlbum != 0 ? songs.Where(song => song.Album.Title == selectedAlbum) : songs; IEnumerable <Song> allFiltered = vm.SelectedBand != 0 ? albumsFiltered.Where(song => song.Album.Band.Name == selectedBand) : albumsFiltered; var userPlaylists = await GetUserPlayLists(userId); var songModels = new List <SongIndexViewModel>(); foreach (var song in allFiltered) { if (song.Hidden) { songModels.Add(new SongIndexViewModel { Hidden = true, Id = song.Id, }); } else { var model = new SongIndexViewModel { Id = song.Id, Hidden = false, SongTitle = song.Title, Duration = song.Duration, }; if (song.Album != null) { model.AlbumId = song.AlbumId; model.AlbumTitle = song.Album.Title; model.ReleaseDate = song.Album.ReleaseDate; if (song.Album.Band != null) { model.BandName = song.Album.Band.Name; } } songModels.Add(model); } } var newVm = new MusicIndexViewModel { Songs = songModels, PlayLists = userPlaylists, BandNames = bandSelectList, AlbumTitles = albumSelectList, }; return(View(newVm)); }