@page "/ffmpeg/{Id:int}" @page "/ffmpeg/add" @using ErsatzTV.Application.Resolutions @using ErsatzTV.Application.Resolutions.Queries @using ErsatzTV.Application.FFmpegProfiles @using ErsatzTV.Application.FFmpegProfiles.Commands @using ErsatzTV.Application.FFmpegProfiles.Queries @inject NavigationManager NavigationManager @inject ILogger Logger @inject ISnackbar Snackbar @inject IMediator Mediator @(IsEdit ? "Edit FFmpeg Profile" : "Add FFmpeg Profile") General @foreach (ResolutionViewModel resolution in _resolutions) { @resolution.Name } Video @foreach (HardwareAccelerationKind hwAccel in Enum.GetValues()) { @hwAccel } Audio @(IsEdit ? "Save Changes" : "Add Profile") @code { [Parameter] public int Id { get; set; } private FFmpegProfileEditViewModel _model = new(); private EditContext _editContext; private ValidationMessageStore _messageStore; private List _resolutions; protected override async Task OnParametersSetAsync() { _resolutions = await Mediator.Send(new GetAllResolutions()); if (IsEdit) { Option profile = await Mediator.Send(new GetFFmpegProfileById(Id)); profile.Match( ffmpegProfileViewModel => _model = new FFmpegProfileEditViewModel(ffmpegProfileViewModel), () => NavigationManager.NavigateTo("404")); } else { _model = new FFmpegProfileEditViewModel(await Mediator.Send(new NewFFmpegProfile())); } _editContext = new EditContext(_model); _messageStore = new ValidationMessageStore(_editContext); } private bool IsEdit => Id != 0; private async Task HandleSubmitAsync() { _messageStore.Clear(); if (_editContext.Validate()) { Seq errorMessage = IsEdit ? (await Mediator.Send(_model.ToUpdate())).LeftToSeq() : (await Mediator.Send(_model.ToCreate())).LeftToSeq(); errorMessage.HeadOrNone().Match( error => { Snackbar.Add("Unexpected error saving ffmpeg profile"); Logger.LogError("Unexpected error saving ffmpeg profile: {Error}", error.Value); }, () => NavigationManager.NavigateTo("/ffmpeg")); } } }