public async Task <IActionResult> Index() { var user = await _userManager.GetUserAsync(HttpContext.User); List <Album> albums = await _repository.GetAllAlbumsAsync(user.Id); Models.AlbumViewModels.IndexViewModel model = new IndexViewModel(); foreach (Album album in albums) { AlbumViewModel viewModel = new AlbumViewModel(album.Id, album.DateCreated, album.Owner, album.Name); List <Photo> photos = await _repository.GetPhotosAsync(album.Id); if (photos.Count > 0) { viewModel.ThumbnailImage = photos.First().ThumbnailImage; } model.Albums.Add(viewModel); } return(View(model)); }