@page "/sites" @attribute [Authorize] @using BLAIzor.Components.Layout @using BLAIzor.Models @using BLAIzor.Services @using Microsoft.AspNetCore.Components.Authorization @layout AdminLayout @inject ScopedContentService SiteInfoService @inject ContentService ContentService @inject NavigationManager NavigationManager @inject AuthenticationStateProvider AuthenticationStateProvider @inject CustomAuthenticationStateProvider CustomAuthProvider @inject IJSRuntime JSRuntime

Your Sites

Change("Panel expanded")) Collapse=@(() => Change("Panel collapsed"))> New site
@if (siteInfoList.Any()) { Change("Panel expanded")) Collapse=@(() => Change("Panel collapsed"))> Sites created @siteInfoList.Count() Sites @* foreach (var item in siteInfoList) {
} *@ } else {

No sites created yet.

}
@code { private IEnumerable siteInfoList = new List(); private SiteInfo newSite = new(); private string? userId; private string? userName; private AuthenticationState? authState; int position = 1; void Change(string text) { Console.Write($"{text}"); } private void visit(SiteInfo site) { SiteInfoService.SelectedBrandName = site.SiteName; SiteInfoService.SelectedSiteId = site.Id; NavigationManager.NavigateTo(site.DefaultUrl, true); } private async Task Preview(SiteInfo site) { string myUrl = $"/preview/{site.Id}"; try { await JSRuntime.InvokeVoidAsync("open", myUrl, "_blank"); } catch (Exception ex) { Console.WriteLine($"Error opening new tab: {ex.Message}"); } } protected override async Task OnInitializedAsync() { authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); if (authState.User.Identity?.IsAuthenticated == true) { userId = CustomAuthProvider.GetUserId(); userName = CustomAuthProvider.GetUserName(); } siteInfoList = await SiteInfoService.GetUserSitesAsync(userId!); } private async Task HandleValidSubmit() { newSite.UserId = userId; newSite.TemplateId = 1; newSite.DefaultUrl = await GenerateSubdomainAsync(newSite.SiteName); var result = await SiteInfoService.AddSiteInfoAsync(newSite); siteInfoList = await SiteInfoService.GetUserSitesAsync(userId!); newSite = new(); // Reset the form } public async Task GenerateSubdomainAsync(string siteName) { var normalizedSiteName = siteName.ToLower() .Replace(" ", "-") .Replace("_", "-") .Replace(".", "-"); var subdomain = $"{normalizedSiteName}.seemgen.com"; // var site = await SiteInfoService.GetSiteInfoByIdAsync(siteId); // if (site != null) // { // site.DefaultUrl = subdomain; // await SiteInfoService.UpdateSiteInfoAsync(site); // } return subdomain; } }