SeemGen/Components/Pages/ManageSiteInfo.razor

67 lines
2.1 KiB
Plaintext

@page "/site-info/{SiteId:int}"
@attribute [Authorize]
@using BLAIzor.Components.Layout
@using BLAIzor.Models
@using BLAIzor.Services
@using Microsoft.AspNetCore.Components.Authorization
@layout AdminLayout
@inject ScopedContentService SiteInfoService
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject CustomAuthenticationStateProvider CustomAuthProvider
<h3>Site Information</h3>
<EditForm Model="@siteInfo" OnValidSubmit="SaveSiteInfo">
<label>
Brand name:
<InputText class="form-control my-3" id="siteName" @bind-Value="siteInfo.SiteName" />
</label>
<label>
Logo url:
<InputText class="form-control my-3" id="brandLogoUrl" @bind-Value="siteInfo.BrandLogoUrl" />
</label>
<label>
Default color
<InputText class="form-control my-3" id="defaultColor" @bind-Value="siteInfo.DefaultColor" />
</label>
<label>
Your domain url
<InputText class="form-control my-3" id="domainUrl" @bind-Value="siteInfo.DomainUrl" />
</label>
<label>
Chosen template
<InputNumber class="form-control my-3" id="templateId" @bind-Value="siteInfo.TemplateId" />
</label>
<label>
Published
<InputCheckbox class="my-3" id="ispublished" @bind-Value="siteInfo.IsPublished" />
</label>
<button class="btn btn-primary" type="submit">Save</button>
</EditForm>
@code {
[Parameter]
public int SiteId { get; set; }
private SiteInfo siteInfo = new();
private string? userId;
private string? userName;
private AuthenticationState? authState;
protected override async Task OnParametersSetAsync()
{
authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity?.IsAuthenticated == true)
{
userId = CustomAuthProvider.GetUserId();
userName = CustomAuthProvider.GetUserName();
}
siteInfo = await SiteInfoService.GetSiteInfoByIdAsync(SiteId) ?? new SiteInfo();
}
private async Task SaveSiteInfo()
{
await SiteInfoService.UpdateSiteInfoAsync(siteInfo);
}
}