69 lines
2.2 KiB
Plaintext
69 lines
2.2 KiB
Plaintext
@page "/admin/blog/create"
|
|
@attribute [Authorize]
|
|
@using TaxBaik.Application.DTOs
|
|
@using TaxBaik.Web.Components.Admin.Pages.Blog
|
|
@inject IBlogBrowserClient BlogClient
|
|
@inject ICategoryBrowserClient CategoryClient
|
|
@inject NavigationManager Navigation
|
|
@inject ISnackbar Snackbar
|
|
|
|
<PageTitle>새 포스트 작성</PageTitle>
|
|
|
|
<section class="admin-page-hero">
|
|
<div>
|
|
<MudText Typo="Typo.caption" Class="admin-eyebrow">Content</MudText>
|
|
<MudText Typo="Typo.h4" Class="admin-page-title">새 포스트 작성</MudText>
|
|
<MudText Typo="Typo.body2" Class="admin-page-subtitle">새로운 블로그 포스트를 작성합니다.</MudText>
|
|
</div>
|
|
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Close" @onclick="GoBack">취소</MudButton>
|
|
</section>
|
|
|
|
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
|
<BlogForm Model="model" Categories="categories" SubmitText="저장" OnSubmit="SavePost" OnCancel="GoBack" />
|
|
</MudPaper>
|
|
|
|
@code {
|
|
private IReadOnlyList<Domain.Entities.Category> categories = [];
|
|
private BlogForm.BlogFormModel model = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
categories = await CategoryClient.GetAllAsync();
|
|
}
|
|
|
|
private void GoBack()
|
|
{
|
|
Navigation.NavigateTo("/taxbaik/admin/blog");
|
|
}
|
|
|
|
private async Task SavePost()
|
|
{
|
|
try
|
|
{
|
|
var result = await BlogClient.CreateAsync(new CreateBlogPostDto
|
|
{
|
|
Title = model.Title,
|
|
Content = model.Content,
|
|
CategoryId = model.CategoryId,
|
|
Tags = model.Tags,
|
|
SeoTitle = model.SeoTitle,
|
|
SeoDescription = model.SeoDescription,
|
|
IsPublished = model.IsPublished
|
|
});
|
|
|
|
if (result == null)
|
|
{
|
|
Snackbar.Add("포스트 저장에 실패했습니다.", Severity.Error);
|
|
return;
|
|
}
|
|
|
|
Snackbar.Add("포스트가 저장되었습니다.", Severity.Success);
|
|
Navigation.NavigateTo("/taxbaik/admin/blog");
|
|
}
|
|
catch (ValidationException ex)
|
|
{
|
|
Snackbar.Add(ex.Message, Severity.Error);
|
|
}
|
|
}
|
|
}
|