122 lines
3.7 KiB
Plaintext
122 lines
3.7 KiB
Plaintext
@page "/admin/companies/{id:int}/edit"
|
|
@attribute [Authorize]
|
|
@using TaxBaik.Web.Components.Admin.Forms
|
|
@inject IApiClient ApiClient
|
|
@inject NavigationManager Navigation
|
|
@inject IJSRuntime JS
|
|
|
|
<PageTitle>고객사 수정</PageTitle>
|
|
|
|
<section class="admin-page-hero">
|
|
<div>
|
|
<div class="admin-eyebrow">Settings</div>
|
|
<h1 class="admin-page-title">고객사 수정</h1>
|
|
<p class="admin-page-subtitle">고객사 정보를 수정합니다.</p>
|
|
</div>
|
|
<button type="button" class="site-button secondary" @onclick="GoBack">취소</button>
|
|
</section>
|
|
|
|
@if (isLoading)
|
|
{
|
|
<div class="admin-surface mt-4">
|
|
<Skeleton Count="4" CssClass="taxbaik-skeleton-grid" />
|
|
</div>
|
|
}
|
|
else if (formModel == null)
|
|
{
|
|
<div class="admin-surface mt-4">고객사를 찾을 수 없습니다.</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="admin-surface mt-4">
|
|
<CompanyForm ButtonText="수정" InitialData="formModel" OnSubmit="HandleUpdate" OnCancel="GoBack" />
|
|
<div class="mt-4">
|
|
<button type="button" class="site-button secondary danger" @onclick="DeleteCompany">고객사 삭제</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter]
|
|
public int Id { get; set; }
|
|
|
|
private CompanyForm.CompanyFormModel? formModel;
|
|
private bool isLoading = true;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var company = await ApiClient.GetAsync<dynamic>($"company/{Id}");
|
|
IDictionary<string, object>? dict = company as IDictionary<string, object>;
|
|
if (dict != null)
|
|
{
|
|
formModel = new CompanyForm.CompanyFormModel
|
|
{
|
|
CompanyCode = (string)dict["companyCode"],
|
|
CompanyName = (string)dict["companyName"],
|
|
ContactPerson = (string?)dict["contactPerson"],
|
|
Phone = (string?)dict["phone"],
|
|
Email = (string?)dict["email"],
|
|
Memo = (string?)dict["memo"],
|
|
IsActive = (bool)(dynamic)dict["isActive"]
|
|
};
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await JS.InvokeVoidAsync("alert", $"고객사 로드 실패: {ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
isLoading = false;
|
|
}
|
|
}
|
|
|
|
private void GoBack()
|
|
{
|
|
Navigation.NavigateTo("/taxbaik/admin/companies");
|
|
}
|
|
|
|
private async Task HandleUpdate(CompanyForm.CompanyFormModel model)
|
|
{
|
|
try
|
|
{
|
|
await ApiClient.PutAsync<object>($"company/{Id}", new
|
|
{
|
|
companyCode = model.CompanyCode,
|
|
companyName = model.CompanyName,
|
|
contactPerson = model.ContactPerson,
|
|
phone = model.Phone,
|
|
email = model.Email,
|
|
memo = model.Memo,
|
|
isActive = model.IsActive
|
|
});
|
|
|
|
await JS.InvokeVoidAsync("alert", "고객사가 수정되었습니다.");
|
|
Navigation.NavigateTo("/taxbaik/admin/companies");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await JS.InvokeVoidAsync("alert", $"수정 실패: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private async Task DeleteCompany()
|
|
{
|
|
if (!await JS.InvokeAsync<bool>("confirm", "정말 삭제하시겠습니까? 이 작업은 취소할 수 없습니다."))
|
|
return;
|
|
|
|
try
|
|
{
|
|
await ApiClient.DeleteAsync($"company/{Id}");
|
|
await JS.InvokeVoidAsync("alert", "고객사가 삭제되었습니다.");
|
|
Navigation.NavigateTo("/taxbaik/admin/companies");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await JS.InvokeVoidAsync("alert", $"삭제 실패: {ex.Message}");
|
|
}
|
|
}
|
|
}
|