From 7bd44091cf28e1e9c9c15b7664776942e4ffff29 Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 12 Mar 2020 22:24:44 +0100 Subject: [PATCH] Show episode count for each season --- EstusShots.Gtk/Pages/EnemiesPage.cs | 2 +- EstusShots.Gtk/Pages/SeasonsPage.cs | 3 ++- EstusShots.Server/Mapping/Profiles.cs | 3 ++- EstusShots.Server/Services/SeasonsService.cs | 4 +++- EstusShots.Shared/Dto/Season.cs | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/EstusShots.Gtk/Pages/EnemiesPage.cs b/EstusShots.Gtk/Pages/EnemiesPage.cs index da8ea9b..86fbbe5 100644 --- a/EstusShots.Gtk/Pages/EnemiesPage.cs +++ b/EstusShots.Gtk/Pages/EnemiesPage.cs @@ -29,7 +29,7 @@ namespace EstusShots.Gtk new DataColumnText(nameof(Enemy.Seasons)) { Title = "Game", - DisplayConverter = seasons => string.Join(", ", ((IEnumerable) seasons).Select(x => x.Game)) + DisplayConverter = seasons => ((IEnumerable) seasons)?.Select(x => x.Game).StringJoin(", ") } }; _enemiesControl = new BindableListControl(columns, nameof(Enemy.EnemyId), _enemiesTreeView); diff --git a/EstusShots.Gtk/Pages/SeasonsPage.cs b/EstusShots.Gtk/Pages/SeasonsPage.cs index 1effad0..bbce51d 100644 --- a/EstusShots.Gtk/Pages/SeasonsPage.cs +++ b/EstusShots.Gtk/Pages/SeasonsPage.cs @@ -116,7 +116,8 @@ namespace EstusShots.Gtk new DataColumnText(nameof(Season.End)) { DisplayConverter = date => (date as DateTime?)?.ToString("dd.MM.yyyy") ?? "Ongoing" - } + }, + new DataColumnText(nameof(Season.EpisodeCount)) {Title = "Episode Count"} }; SeasonsControl = new BindableListControl(columns, nameof(Season.SeasonId), SeasonsView); SeasonsControl.SelectionChanged += SeasonsControlSelectionChanged; diff --git a/EstusShots.Server/Mapping/Profiles.cs b/EstusShots.Server/Mapping/Profiles.cs index ea08470..b738bc7 100644 --- a/EstusShots.Server/Mapping/Profiles.cs +++ b/EstusShots.Server/Mapping/Profiles.cs @@ -8,7 +8,8 @@ namespace EstusShots.Server.Mapping { public Profiles() { - CreateMap(); + CreateMap() + .ForMember(x => x.EpisodeCount, y => y.MapFrom(z => z.Episodes.Count)); CreateMap(); CreateMap(); diff --git a/EstusShots.Server/Services/SeasonsService.cs b/EstusShots.Server/Services/SeasonsService.cs index 3313ce8..a13f6f0 100644 --- a/EstusShots.Server/Services/SeasonsService.cs +++ b/EstusShots.Server/Services/SeasonsService.cs @@ -27,7 +27,9 @@ namespace EstusShots.Server.Services public async Task> GetSeasons(GetSeasonsParameter parameter) { - var seasons = await _context.Seasons.ToListAsync(); + var seasons = await _context.Seasons + .Include(season => season.Episodes) + .ToListAsync(); var dtos = _mapper.Map>(seasons); return new ApiResponse(new GetSeasonsResponse(dtos)); } diff --git a/EstusShots.Shared/Dto/Season.cs b/EstusShots.Shared/Dto/Season.cs index 76fcadc..4d77048 100644 --- a/EstusShots.Shared/Dto/Season.cs +++ b/EstusShots.Shared/Dto/Season.cs @@ -16,6 +16,8 @@ namespace EstusShots.Shared.Dto public DateTime? End { get; set; } + public int EpisodeCount { get; set; } + public string DisplayName => $"S{Number:D2} {Game}"; } } \ No newline at end of file