@using Core.Entities @using WebApp.Services @using PSC.Blazor.Components.MarkdownEditor @using MudBlazor @inject INotesService NotesService @inject ISnackbar Snackbar @inject IDialogService DialogService Content (Markdown) Cancel Save @code { [CascadingParameter] IMudDialogInstance MudDialog { get; set; } = null!; [Parameter] public Note Note { get; set; } = null!; [Parameter] public bool IsEdit { get; set; } private Note _note = null!; protected override void OnInitialized() { _note = new Note { Id = Note.Id, Title = Note.Title ?? "", Content = Note.Content ?? "" }; } private async Task Save() { if (string.IsNullOrWhiteSpace(_note.Title)) { Snackbar.Add("Title is required", Severity.Warning); return; } try { if (IsEdit) { await NotesService.UpdateNoteAsync(_note); Snackbar.Add("Note updated successfully", Severity.Success); } else { await NotesService.CreateNoteAsync(_note); Snackbar.Add("Note created successfully", Severity.Success); } MudDialog.Close(DialogResult.Ok(true)); } catch (Exception ex) { Snackbar.Add($"Error saving note: {ex.Message}", Severity.Error); } } private void Cancel() { MudDialog.Cancel(); } }