public async Task <IActionResult> Index(string searchName = "") { var allSongs = _dbContext.Songs.ToList(); allSongs = allSongs.OrderBy(x => x.Name).ToList(); if (searchName != null && searchName != "") { allSongs = allSongs.Where(x => x.Name.Contains(searchName)).ToList(); } var model = new SongsAllViewModel() { Songs = new List <SongsViewModel>() }; foreach (var song in allSongs) { var singleViewModel = new SongsViewModel() { Id = song.Id, Name = song.Name, Duration = FormatDuration(song.DurationSeconds), AlbumId = song.AlbumId, PerformerId = song.PerformerId, AlbumName = (await _dbContext.Albums.FindAsync(song.AlbumId)).Name, PerformerName = (await _dbContext.Performers.FindAsync(song.PerformerId)).Name, }; model.Songs.Add(singleViewModel); } return(View(model)); }
public async Task <IActionResult> Index(SongsAllViewModel model) { return(await this.Index(model.SearchWord)); }