From 57aa14b7649b6f4a0447aa362d42da96b4db5363 Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Mon, 14 Jun 2021 18:31:50 -0500 Subject: [PATCH] fix adding channel with no watermark (#265) --- CHANGELOG.md | 4 +++- .../Channels/Commands/CreateChannelHandler.cs | 16 ++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 353d68fc6..d0bb5fbb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fix ui crash adding a channel without a watermark ## [0.0.46-prealpha] - 2021-06-14 ### Added @@ -18,7 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - This allows easy watermark reuse across channels ### Fixed -- Fix crash adding or editing schedule items due to Artist with no name +- Fix ui crash adding or editing schedule items due to Artist with no name - Fix many potential sources of inconsistent data in UI ## [0.0.45-prealpha] - 2021-06-12 diff --git a/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs b/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs index 5bf4515a2..3e55b0ed5 100644 --- a/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs +++ b/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs @@ -38,7 +38,7 @@ namespace ErsatzTV.Application.Channels.Commands return new CreateChannelResult(channel.Id); } - private async Task> Validate(TvContext dbContext, CreateChannel request) => + private static async Task> Validate(TvContext dbContext, CreateChannel request) => (ValidateName(request), await ValidateNumber(dbContext, request), await FFmpegProfileMustExist(dbContext, request), ValidatePreferredLanguage(request), @@ -66,10 +66,14 @@ namespace ErsatzTV.Application.Channels.Commands FFmpegProfileId = ffmpegProfileId, StreamingMode = request.StreamingMode, Artwork = artwork, - PreferredLanguageCode = preferredLanguageCode, - WatermarkId = watermarkId + PreferredLanguageCode = preferredLanguageCode }; + foreach (int id in watermarkId) + { + channel.WatermarkId = id; + } + return channel; }); @@ -111,20 +115,20 @@ namespace ErsatzTV.Application.Channels.Commands .MapT(_ => createChannel.FFmpegProfileId) .Map(o => o.ToValidation($"FFmpegProfile {createChannel.FFmpegProfileId} does not exist.")); - private static async Task> WatermarkMustExist( + private static async Task>> WatermarkMustExist( TvContext dbContext, CreateChannel createChannel) { if (createChannel.WatermarkId is null) { - return createChannel.WatermarkId; + return Option.None; } return await dbContext.ChannelWatermarks .CountAsync(w => w.Id == createChannel.WatermarkId) .Map(Optional) .Filter(c => c > 0) - .MapT(_ => createChannel.WatermarkId) + .MapT(_ => Optional(createChannel.WatermarkId)) .Map(o => o.ToValidation($"Watermark {createChannel.WatermarkId} does not exist.")); } }