@page "/admin/blog/create" @attribute [Authorize] @rendermode @(new InteractiveServerRenderMode(prerender: false)) @using TaxBaik.Application.DTOs @using TaxBaik.Application.Services @using TaxBaik.Domain.Interfaces @inject BlogService BlogService @inject ICategoryRepository CategoryRepository @inject NavigationManager Navigation @inject ISnackbar Snackbar 새 포스트 작성
Content 새 포스트 작성 새로운 블로그 포스트를 작성합니다.
취소
@foreach (var category in categories) { @category.Name }
저장
@code { private MudForm? form; private List categories = []; private CreatePostModel model = new(); private EasyMDE.Editor? editor; [Inject] private IJSRuntime JS { get; set; } = null!; protected override async Task OnInitializedAsync() { categories = (await CategoryRepository.GetAllAsync()).ToList(); } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await JS.InvokeVoidAsync("window.initMarkdownEditor", "markdown-editor", model.Content ?? ""); } } private void GoBack() { Navigation.NavigateTo("/taxbaik/admin/blog"); } private async Task SavePost() { if (form == null) return; // 에디터에서 최신 내용 가져오기 model.Content = await JS.InvokeAsync("window.getMarkdownContent"); if (string.IsNullOrWhiteSpace(model.Content)) { Snackbar.Add("본문 내용을 입력하세요.", Severity.Error); return; } await form.Validate(); if (!form.IsValid) return; try { await BlogService.CreateAsync(new CreateBlogPostDto { Title = model.Title, Content = model.Content, CategoryId = model.CategoryId, Tags = model.Tags, SeoTitle = model.SeoTitle, SeoDescription = model.SeoDescription, IsPublished = model.IsPublished }); Snackbar.Add("포스트가 저장되었습니다.", Severity.Success); Navigation.NavigateTo("/taxbaik/admin/blog"); } catch (ValidationException ex) { Snackbar.Add(ex.Message, Severity.Error); } } private class CreatePostModel { public string Title { get; set; } = ""; public string Content { get; set; } = ""; public int? CategoryId { get; set; } public string? Tags { get; set; } public string? SeoTitle { get; set; } public string? SeoDescription { get; set; } public bool IsPublished { get; set; } } }