@page "/searchshows" @using MovieActorLookup.Models @inject ShowService ShowService @inject IJSRuntime JSRuntime @rendermode InteractiveServer

Discover Actors & Their Shows

Search by TV show and character to explore an actor's complete filmography

📺
🎭
@if (_isSearching) {

Finding the perfect match...

} else if (_actor != null) {

@_actor.Name

@_actor.TvCharacters.Count show@(_actor.TvCharacters.Count != 1 ? "s" : "") found
@if (_matchedShow != null) {

Your Search Match

}

Complete TV Filmography

@foreach (var group in _actor.TvCharacters .GroupBy(tc => tc.Franchise) .OrderBy(g => g.Key == "Standalone") .ThenBy(g => g.Key)) { @if (group.Key != "Standalone") {
@group.Key Series
}
@foreach (var show in (group.Key == "Standalone" ? group.OrderByDescending(tc => DateTime.TryParse(tc.FirstAirDate, out var d) ? d : DateTime.MinValue) : group.OrderBy(tc => DateTime.TryParse(tc.FirstAirDate, out var d) ? d : DateTime.MaxValue))) {
@show.ShowTitle Poster
@show.ShowTitle
as @show.CharacterName
@if (!string.IsNullOrEmpty(show.Overview)) {

@show.Overview

@if (show.Overview.Length > 150) { }
}
@show.FirstAirDate
}
}
} else if (!string.IsNullOrEmpty(_tvTitle) || !string.IsNullOrEmpty(_characterName)) {
🔍

No matches found

Try adjusting your search terms or check the spelling

} else {
🎬

Ready to explore?

Enter a TV show title and character name to discover an actor's complete television journey

}
@code { private string _tvTitle = ""; private string _characterName = ""; private Actor _actor; private TvCharacter _matchedShow; private bool _isSearching = false; private HashSet _expandedOverviews = new HashSet(); private bool IsOverviewExpanded(string showTitle) { return _expandedOverviews.Contains(showTitle); } private void ToggleOverview(string showTitle) { if (_expandedOverviews.Contains(showTitle)) { _expandedOverviews.Remove(showTitle); } else { _expandedOverviews.Add(showTitle); } } private async Task SearchForActorAndCharacters() { if (string.IsNullOrWhiteSpace(_tvTitle) || string.IsNullOrWhiteSpace(_characterName)) return; _isSearching = true; _actor = null; _matchedShow = null; StateHasChanged(); // Start animations after a small delay to ensure DOM is ready await Task.Delay(100); await JSRuntime.InvokeVoidAsync("startAnimations"); try { var shows = await ShowService.GetShowsByTitle(_tvTitle); foreach (var show in shows) { var credits = await ShowService.GetShowCreditsById(show.Id); foreach (var cast in credits.Cast) { if (cast.Character.Contains(_characterName, StringComparison.OrdinalIgnoreCase)) { if (_actor == null) { _actor = new Actor(cast.Name); await LoadActorFilmography(cast.Id, (object)show, (object)cast); } break; } } if (_actor != null) break; } } catch (Exception ex) { Console.WriteLine($"Search error: {ex.Message}"); } finally { _isSearching = false; StateHasChanged(); } } private async Task LoadActorFilmography(int personId, object originalShow, object originalCast) { var filmography = await ShowService.GetActorTvCreditsById(personId); if (filmography?.Cast != null) { foreach (var role in filmography.Cast) { var fullShow = await ShowService.GetShowDetailsById(role.Id); var tvCharacter = new TvCharacter { ShowTitle = role.ShowTitle ?? "Unknown Title", CharacterName = role.Character ?? "Unknown Character", ShowPosterPath = role.PosterPath ?? "", FirstAirDate = DateTime.TryParse(fullShow?.FirstAirDate, out var parsedDate) ? parsedDate.ToString("MMM dd, yyyy") : "Unknown Date", Overview = fullShow?.Overview ?? "", Franchise = fullShow?.BelongsToCollection?.Name ?? "Standalone" }; _actor.TvCharacters.Add(tvCharacter); if (_matchedShow == null && string.Equals(role.ShowTitle, GetPropertyValue(originalShow, "Name")?.ToString(), StringComparison.OrdinalIgnoreCase) && string.Equals(role.Character, GetPropertyValue(originalCast, "Character")?.ToString(), StringComparison.OrdinalIgnoreCase)) { _matchedShow = tvCharacter; } } } } private object GetPropertyValue(object obj, string propertyName) { if (obj == null) return null; var property = obj.GetType().GetProperty(propertyName); return property?.GetValue(obj); } }