@page "/design-templates" @using BLAIzor.Components.Layout @using BLAIzor.Models @using BLAIzor.Services @using Microsoft.AspNetCore.Components.Authorization @attribute [Authorize] @layout AdminLayout @inject DesignTemplateService DesignTemplateService @inject CssTemplateService CssTemplateService @inject NavigationManager NavigationManager @inject AuthenticationStateProvider AuthenticationStateProvider @inject CustomAuthenticationStateProvider CustomAuthProvider

Design Template Manager

@if (isLoading) {

Loading...

} else {

Your Templates

@foreach (var template in userTemplates) {
@template.TemplateName
(@template.Status)
design image

Description: @template.Description

Version: @template.Version

}

Create New Template

} @code { private bool isLoading = true; private List userTemplates = new(); private DesignTemplate newTemplate = new(); private CssTemplate newCssTemplate = new(); private AuthenticationState? authState; private string? userId; private string? userName; protected override async Task OnInitializedAsync() { authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); if (authState.User.Identity?.IsAuthenticated == true) { userId = CustomAuthProvider.GetUserId(); userName = CustomAuthProvider.GetUserName(); } await LoadTemplates(); isLoading = false; } private async Task LoadTemplates() { userTemplates = (await DesignTemplateService.GetTemplatesByUserAsync(userId)).ToList(); } private async Task CreateTemplate() { isLoading = true; // Create the CSS template first // var cssTemplate = await CssTemplateService.CreateAsync(newCssTemplate); var LastTemplateId = await DesignTemplateService.GetLastTemplateId(); // Create the design template and link the CSS template newCssTemplate.LastUpdated = DateTime.UtcNow; newTemplate.UserId = userId!; newTemplate.CssTemplate = newCssTemplate; newTemplate.Version = 1; newTemplate.CreatedAt = DateTime.UtcNow; newTemplate.UpdatedAt = DateTime.UtcNow; newTemplate.IsPublished = false; newTemplate.IsDeprecated = false; newTemplate.Status = "Draft"; newTemplate.QDrandCollectionName = "Template" + (LastTemplateId + 1); var result = await DesignTemplateService.CreateAsync(newTemplate); // newTemplate.QDrandCollectionName = "Template"+ result.Id; // Reset form and reload templates newTemplate = new(); newCssTemplate = new(); await LoadTemplates(); isLoading = false; } private async Task EditTemplate(int templateId) { NavigationManager.NavigateTo($"/edit-template/{templateId}"); } private async Task DeleteTemplate(int templateId) { isLoading = true; await DesignTemplateService.DeleteAsync(templateId); await LoadTemplates(); isLoading = false; } }