@page "/media/movies/{MovieId:int}" @using ErsatzTV.Application.Movies @using ErsatzTV.Application.Movies.Queries @using System.Globalization @using ErsatzTV.Application.MediaCards @using ErsatzTV.Application.MediaCollections @using ErsatzTV.Application.MediaCollections.Commands @inject IMediator _mediator @inject IDialogService _dialog @inject NavigationManager _navigationManager
@if (!string.IsNullOrWhiteSpace(_movie.FanArt)) { if (_movie.FanArt.StartsWith("http://") || _movie.FanArt.StartsWith("https://")) { fan art } else { fan art } }
@if (!string.IsNullOrWhiteSpace(_movie.Poster)) { if (_movie.Poster.StartsWith("http://") || _movie.Poster.StartsWith("https://")) { movie poster } else { movie poster } }
@_movie.Title @_movie.Year @if (!string.IsNullOrWhiteSpace(_movie.Plot)) { @_movie.Plot }
Add To Collection
@if (_sortedContentRatings.Any()) {
Content Ratings:  @_sortedContentRatings.Head() @foreach (string contentRating in _sortedContentRatings.Skip(1)) { ,  @contentRating }
} @if (_sortedLanguages.Any()) {
Languages:  @_sortedLanguages.Head().EnglishName @foreach (CultureInfo language in _sortedLanguages.Skip(1)) { ,  @language.EnglishName }
} @if (_sortedStudios.Any()) {
Studios:  @_sortedStudios.Head() @foreach (string studio in _sortedStudios.Skip(1)) { ,  @studio }
} @if (_sortedDirectors.Any()) {
Directors:  @_sortedDirectors.Head() @foreach (string director in _sortedDirectors.Skip(1)) { ,  @director }
} @if (_sortedWriters.Any()) {
Writers:  @_sortedWriters.Head() @foreach (string writer in _sortedWriters.Skip(1)) { ,  @writer }
} @if (_sortedGenres.Any()) {
Genres:  @_sortedGenres.Head() @foreach (string genre in _sortedGenres.Skip(1)) { ,  @genre }
} @if (_sortedTags.Any()) {
Tags:  @_sortedTags.Head() @foreach (string tag in _sortedTags.Skip(1)) { ,  @tag }
}
@if (_movie.Actors.Any()) { Actors @foreach (ActorCardViewModel actor in _movie.Actors) { } } @code { [Parameter] public int MovieId { get; set; } private MovieViewModel _movie; private List _sortedContentRatings = new(); private List _sortedLanguages = new(); private List _sortedDirectors = new(); private List _sortedWriters = new(); private List _sortedStudios = new(); private List _sortedGenres = new(); private List _sortedTags = new(); protected override Task OnParametersSetAsync() => RefreshData(); private Task RefreshData() => _mediator.Send(new GetMovieById(MovieId)).IfSomeAsync(vm => { _movie = vm; _sortedContentRatings = _movie.ContentRatings.OrderBy(cr => cr).ToList(); _sortedLanguages = _movie.Languages.OrderBy(ci => ci.EnglishName).ToList(); _sortedStudios = _movie.Studios.OrderBy(s => s).ToList(); _sortedGenres = _movie.Genres.OrderBy(g => g).ToList(); _sortedTags = _movie.Tags.OrderBy(t => t).ToList(); _sortedDirectors = _movie.Directors.OrderBy(d => d).ToList(); _sortedWriters = _movie.Writers.OrderBy(w => w).ToList(); }); private async Task AddToCollection() { var parameters = new DialogParameters { { "EntityType", "movie" }, { "EntityName", _movie.Title } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Add To Collection", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled && result.Data is MediaCollectionViewModel collection) { await _mediator.Send(new AddMovieToCollection(collection.Id, MovieId)); _navigationManager.NavigateTo($"/media/collections/{collection.Id}"); } } }