mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
using System.Globalization; |
|
using ErsatzTV.Core.Domain; |
|
|
|
namespace ErsatzTV.Application.MediaItems; |
|
|
|
internal static class Mapper |
|
{ |
|
internal static NamedMediaItemViewModel ProjectToViewModel(Show show) => |
|
new(show.Id, show.ShowMetadata.HeadOrNone().Map(sm => $"{sm?.Title} ({sm?.Year})").IfNone("???")); |
|
|
|
internal static NamedMediaItemViewModel ProjectToViewModel(Season season) => |
|
new(season.Id, $"{ShowTitle(season)} - {SeasonDescription(season)}"); |
|
|
|
internal static NamedMediaItemViewModel ProjectToViewModel(Artist artist) => |
|
new(artist.Id, artist.ArtistMetadata.HeadOrNone().Match(am => am.Title, () => "???")); |
|
|
|
private static string ShowTitle(Season season) |
|
{ |
|
var title = "???"; |
|
var year = "???"; |
|
|
|
foreach (ShowMetadata show in season.Show.ShowMetadata.HeadOrNone()) |
|
{ |
|
title = show.Title; |
|
foreach (int y in Optional(show.Year)) |
|
{ |
|
year = y.ToString(CultureInfo.InvariantCulture); |
|
} |
|
} |
|
|
|
return $"{title} ({year})"; |
|
} |
|
|
|
private static string SeasonDescription(Season season) => |
|
season.SeasonNumber == 0 ? "Specials" : $"Season {season.SeasonNumber}"; |
|
}
|
|
|