@inject PowderCoating.Core.Interfaces.ITenantContext TenantContext @inject PowderCoating.Core.Interfaces.IUnitOfWork UnitOfWork @inject PowderCoating.Web.Services.IOnlineUserTracker OnlineUserTracker @inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostEnv @{ string? companyName = null; bool companyHasLogo = false; long logoVersion = 1; var isSuperAdmin = TenantContext.IsSuperAdmin(); var isImpersonating = Context.Session.GetString("ImpersonatingCompanyName") != null; // While impersonating, treat the session as a regular company user (not platform admin) var isPlatformAdmin = TenantContext.IsPlatformAdmin() && !isImpersonating; var theme = User.FindFirst("Theme")?.Value ?? "light"; var sidebarColor = User.FindFirst("SidebarColor")?.Value ?? "ocean"; var _surfaceCookie = Context.Request.Cookies["pcl_surface"]; var _themeFromClaim = User.FindFirst("Theme")?.Value; // "light" or "dark" from profile var _pclSurface = _surfaceCookie == "ink" ? "ink" : _surfaceCookie == "paper" ? "paper" : _themeFromClaim == "dark" ? "ink" : "paper"; var _bsTheme = (_pclSurface == "ink") ? "dark" : "light"; var hasProfilePic = User.FindFirst("HasProfilePicture")?.Value == "true"; var _envName = _hostEnv.EnvironmentName; // Development, Staging, Production, etc. var _isNonProd = !_hostEnv.IsProduction(); var _envColor = _envName.ToLower() switch { "development" => "#b45309", // amber-700 "staging" => "#7c3aed", // violet-700 "testing" => "#0369a1", // sky-700 _ => "#374151" // gray-700 for anything else }; if (User.Identity?.IsAuthenticated == true) { if (isImpersonating) { // Show impersonated company name and logo in sidebar companyName = Context.Session.GetString("ImpersonatingCompanyName"); var impersonatedId = Context.Session.GetInt32("ImpersonatingCompanyId"); if (impersonatedId.HasValue) { var company = await UnitOfWork.Companies.GetByIdAsync(impersonatedId.Value, ignoreQueryFilters: true); if (company != null) { companyHasLogo = !string.IsNullOrEmpty(company.LogoFilePath) || (company.LogoData?.Length > 0); logoVersion = (company.UpdatedAt ?? DateTime.UtcNow).Ticks; } } } else { var companyId = TenantContext.GetCurrentCompanyId(); if (isPlatformAdmin) { // Platform admins (demo company) see "Super Admin Mode" companyName = "Super Admin Mode"; // Can still see their assigned company's logo if (companyId.HasValue && companyId.Value > 0) { var company = await UnitOfWork.Companies.GetByIdAsync(companyId.Value, ignoreQueryFilters: true); if (company != null && (!string.IsNullOrEmpty(company.LogoFilePath) || (company.LogoData != null && company.LogoData.Length > 0))) { companyHasLogo = true; logoVersion = (company.UpdatedAt ?? DateTime.UtcNow).Ticks; } } } else { // Regular users AND company SuperAdmins see their real company name and logo if (companyId.HasValue && companyId.Value > 0) { var company = await UnitOfWork.Companies.GetByIdAsync(companyId.Value, ignoreQueryFilters: true); if (company != null) { companyName = company.CompanyName; companyHasLogo = !string.IsNullOrEmpty(company.LogoFilePath) || (company.LogoData != null && company.LogoData.Length > 0); logoVersion = (company.UpdatedAt ?? DateTime.UtcNow).Ticks; } else { companyName = "No Company"; } } else { companyName = "No Company"; } } } } }