first push

This commit is contained in:
2025-05-06 10:37:33 -04:00
parent 2b1ec3ee26
commit 74efad656a
35 changed files with 1686 additions and 0 deletions
@@ -0,0 +1,19 @@
@page "/counter"
@rendermode InteractiveServer
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
@@ -0,0 +1,7 @@
@page "/"
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
@@ -0,0 +1,156 @@
@page "/searchmovies"
@using MovieActorLookup.Models
@using MovieActorLookup.Models.Movies
@using System.ComponentModel.DataAnnotations
@inject MovieService MovieService
@rendermode InteractiveServer
<h3>Search for Actor by Movie and Character Name</h3>
<div class="mb-3">
<input type="text" class="form-control" @bind="_movieTitle" placeholder="Enter movie title..." />
<input type="text" class="form-control" @bind="_characterName" placeholder="Enter character name..." />
<button class="btn btn-primary mt-2" @onclick="SearchForActorAndCharacters">Search</button>
</div>
@if (_isSearching)
{
<p>Searching...</p>
}
else if (_actor != null)
{
<h4>Actor: @_actor.Name</h4>
@if (_matchedMovie != null)
{
<div class="card m-2" style="width: 18rem;">
<img class="card-img-top" src="@($"https://image.tmdb.org/t/p/w500{_matchedMovie.MoviePosterPath}")" alt="Movie Poster">
<div class="card-body">
<h5 class="card-title">@_matchedMovie.MovieTitle</h5>
<h10 class="card-text">@_matchedMovie.CharacterName</h10>
<br />
<small class="card-text">@_matchedMovie.Franchise</small>
<small class="text-muted">Release Date: @_matchedMovie.ReleaseDate</small>
</div>
</div>
}
@foreach (var franchiseGroup in _actor.MovieCharacters
.GroupBy(mc => mc.Franchise)
.OrderBy(g => g.Key == "Standalone")
.ThenBy(g => g.Key))
{
<h5 class="mt-4">@franchiseGroup.Key</h5>
<div class="d-flex flex-wrap">
@foreach (var movieCharacter in (franchiseGroup.Key == "Standalone"
? franchiseGroup.OrderByDescending(mc =>
DateTime.TryParse(mc.ReleaseDate, out var d) ? d : DateTime.MinValue)
: franchiseGroup.OrderBy(mc =>
DateTime.TryParse(mc.ReleaseDate, out var d) ? d : DateTime.MaxValue)))
{
<div class="card m-2" style="width: 18rem;">
<img class="card-img-top" src="@($"https://image.tmdb.org/t/p/w500{movieCharacter.MoviePosterPath}")" alt="Movie Poster">
<div class="card-body">
<h5 class="card-title">@movieCharacter.MovieTitle</h5>
<h10 class="card-text">@movieCharacter.CharacterName</h10>
<p class="text-muted">@movieCharacter.Overview</p>
<small class="text-muted">Release Date: @movieCharacter.ReleaseDate</small>
</div>
</div>
}
</div>
}
}
else
{
<p>Enter a movie title and character name to begin your search.</p>
}
@code {
private string _movieTitle;
private string _characterName;
private Actor _actor;
private MovieCharacter _matchedMovie;
private bool _isSearching = false;
private async Task SearchForActorAndCharacters()
{
_isSearching = true;
_actor = null;
_matchedMovie = null; // reset matched movie
StateHasChanged();
if (!string.IsNullOrWhiteSpace(_movieTitle) && !string.IsNullOrWhiteSpace(_characterName))
{
var movies = await MovieService.GetMoviesByTitle(_movieTitle);
foreach (var movie in movies)
{
var credits = await MovieService.GetMovieCreditsByMovieId(movie.Id);
foreach (var castMember in credits.Cast)
{
if (castMember.Character.ToLower().Contains(_characterName.ToLower()))
{
if (_actor == null)
{
_actor = new Actor(castMember.Name);
int personId = castMember.Id;
var filmography = await MovieService.GetActorMovieCreditsById(personId);
if (filmography?.Cast != null)
{
foreach (var role in filmography.Cast)
{
var fullMovie = await MovieService.GetMovieDetailsById(role.Id);
var movieCharacter = new MovieCharacter
{
MovieTitle = role.Title,
CharacterName = role.Character,
MoviePosterPath = role.PosterPath,
ReleaseDate = DateTime.TryParse(fullMovie?.ReleaseDate, out var parsedDate)
? parsedDate.ToString("MM/dd/yyyy")
: "N/A",
Overview = fullMovie?.Overview ?? "",
Franchise = fullMovie?.BelongsToCollection?.Name ?? "Standalone"
};
_actor.MovieCharacters.Add(movieCharacter);
if (_matchedMovie == null)
{
if (role.Title == movie.Title && role.Character == castMember.Character)
{
_matchedMovie = movieCharacter;
}
}
}
}
}
}
}
}
}
_isSearching = false;
StateHasChanged();
}
private async Task<Movie> GetProperMovieBasedOffOfActorInvolvement(string movieActorTitle, CastMember actor)
{
List<Credits> overallCredits = new();
List<Movie> actorMovies = await MovieService.GetMoviesByTitle(movieActorTitle);
foreach (Movie movie in actorMovies)
{
overallCredits.Add(await MovieService.GetMovieCreditsByMovieId(movie.Id));
}
Credits actorMovieCredits = overallCredits.FirstOrDefault(x => x.Cast.Any(c => c.Id == actor.Id));
Movie movie1 = actorMovies.Where(x => x.Id == actorMovieCredits.Id).FirstOrDefault();
return movie1;
}
}
@@ -0,0 +1,130 @@
@page "/searchshows"
@using MovieActorLookup.Models
@inject ShowService ShowService
@rendermode InteractiveServer
<h3>Search for Actor by TV Show and Character Name</h3>
<div class="mb-3">
<input type="text" class="form-control" @bind="_tvTitle" placeholder="Enter show title..." />
<input type="text" class="form-control" @bind="_characterName" placeholder="Enter character name..." />
<button class="btn btn-primary mt-2" @onclick="SearchForActorAndCharacters">Search</button>
</div>
@if (_isSearching)
{
<p>Searching...</p>
}
else if (_actor != null)
{
<h4>Actor: @_actor.Name</h4>
@if (_matchedShow != null)
{
<div class="card m-2" style="width: 18rem;">
<img class="card-img-top" src="@($"https://image.tmdb.org/t/p/w500{_matchedShow.ShowPosterPath}")" alt="Show Poster">
<div class="card-body">
<h5 class="card-title">@_matchedShow.ShowTitle</h5>
<h10 class="card-text">@_matchedShow.CharacterName</h10>
<br />
<small class="text-muted">First Air Date: @_matchedShow.FirstAirDate</small>
</div>
</div>
}
@foreach (var group in _actor.TvCharacters
.GroupBy(tc => tc.Franchise)
.OrderBy(g => g.Key == "Standalone")
.ThenBy(g => g.Key))
{
<div class="d-flex flex-wrap">
@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)))
{
<div class="card m-2" style="width: 18rem;">
<img class="card-img-top" src="@($"https://image.tmdb.org/t/p/w500{show.ShowPosterPath}")" alt="Poster">
<div class="card-body">
<h5 class="card-title">@show.ShowTitle</h5>
<h10 class="card-text">@show.CharacterName</h10>
<p class="text-muted">@show.Overview</p>
<small class="text-muted">First Air Date: @show.FirstAirDate</small>
</div>
</div>
}
</div>
}
}
else
{
<p>Enter a TV show title and character name to begin your search.</p>
}
@code {
private string _tvTitle;
private string _characterName;
private Actor _actor;
private TvCharacter _matchedShow;
private bool _isSearching = false;
private async Task SearchForActorAndCharacters()
{
_isSearching = true;
_actor = null;
_matchedShow = null;
StateHasChanged();
if (!string.IsNullOrWhiteSpace(_tvTitle) && !string.IsNullOrWhiteSpace(_characterName))
{
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.ToLower().Contains(_characterName.ToLower()))
{
if (_actor == null)
{
_actor = new Actor(cast.Name);
int personId = cast.Id;
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,
CharacterName = role.Character,
ShowPosterPath = role.PosterPath,
FirstAirDate = DateTime.TryParse(fullShow?.FirstAirDate, out var parsedDate)
? parsedDate.ToString("MM/dd/yyyy")
: "N/A",
Overview = fullShow?.Overview ?? "",
Franchise = fullShow?.BelongsToCollection?.Name ?? "Standalone"
};
_actor.TvCharacters.Add(tvCharacter);
if (_matchedShow == null &&
role.ShowTitle == show.Name &&
role.Character == cast.Character)
{
_matchedShow = tvCharacter;
}
}
}
}
}
}
}
}
_isSearching = false;
StateHasChanged();
}
}
@@ -0,0 +1,64 @@
@page "/weather"
@attribute [StreamRendering]
<PageTitle>Weather</PageTitle>
<h1>Weather</h1>
<p>This component demonstrates showing data.</p>
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}