89 lines
3.4 KiB
Plaintext
89 lines
3.4 KiB
Plaintext
@page "/admin/blog/create"
|
|
@attribute [Authorize]
|
|
@using TaxBaik.Application.DTOs
|
|
@using TaxBaik.Application.Services
|
|
@using TaxBaik.Domain.Interfaces
|
|
@inject BlogService BlogService
|
|
@inject ICategoryRepository CategoryRepository
|
|
@inject NavigationManager Navigation
|
|
@inject IJSRuntime JS
|
|
|
|
<PageTitle>새 포스트 작성</PageTitle>
|
|
<section class="admin-page-hero">
|
|
<div>
|
|
<div class="admin-eyebrow">Content</div>
|
|
<h1 class="admin-page-title">새 포스트 작성</h1>
|
|
<p class="admin-page-subtitle">새로운 블로그 포스트를 작성합니다.</p>
|
|
</div>
|
|
<button type="button" class="site-button secondary" @onclick='() => Navigation.NavigateTo("/taxbaik/admin/blog")'>취소</button>
|
|
</section>
|
|
|
|
<div class="admin-surface mt-4">
|
|
<form class="admin-dialog-card" @onsubmit="SavePost" @onsubmit:preventDefault="true">
|
|
<label>제목 * <input class="admin-input" @bind="model.Title" /></label>
|
|
<label>카테고리
|
|
<select class="admin-input" @bind="CategoryIdText">
|
|
<option value="">선택하세요</option>
|
|
@foreach (var category in categories)
|
|
{
|
|
<option value="@category.Id.ToString()">@category.Name</option>
|
|
}
|
|
</select>
|
|
</label>
|
|
<label>본문 * <textarea class="admin-input" rows="10" @bind="model.Content"></textarea></label>
|
|
<label>태그 (쉼표로 구분) <input class="admin-input" @bind="model.Tags" /></label>
|
|
<label>SEO 제목 <input class="admin-input" @bind="model.SeoTitle" /></label>
|
|
<label>SEO 설명 <textarea class="admin-input" rows="3" @bind="model.SeoDescription"></textarea></label>
|
|
<label><input type="checkbox" @bind="model.IsPublished" /> 즉시 발행</label>
|
|
<div class="admin-dialog-actions">
|
|
<button type="submit" class="site-button primary">저장</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
@code {
|
|
private List<Domain.Entities.Category> categories = [];
|
|
private CreatePostModel model = new();
|
|
private string CategoryIdText { get => model.CategoryId?.ToString() ?? ""; set => model.CategoryId = int.TryParse(value, out var id) ? id : null; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
categories = (await CategoryRepository.GetAllAsync()).ToList();
|
|
}
|
|
|
|
private async Task SavePost()
|
|
{
|
|
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
|
|
});
|
|
|
|
await JS.InvokeVoidAsync("alert", "포스트가 저장되었습니다.");
|
|
Navigation.NavigateTo("/taxbaik/admin/blog");
|
|
}
|
|
catch (ValidationException ex)
|
|
{
|
|
await JS.InvokeVoidAsync("alert", ex.Message);
|
|
}
|
|
}
|
|
|
|
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; }
|
|
}
|
|
}
|