using Biskilog_Accounting.Client.Pages.Transactions.Elements ;
using Radzen ;
using System.Net.Http.Headers ;
namespace Biskilog_Accounting.Client.Layouts
{
public partial class MainLayout
{
protected override async Task OnInitializedAsync ( )
{
await CheckPermission ( ) ;
if ( m_http . DefaultRequestHeaders . Authorization ! = null )
{
_ = Task . Run ( async ( ) = >
{
var fetchCompanyData = m_companyInfo . GetCompanyInfoAsync ( ) ;
var fetchBranchData = m_companyInfo . GetBranches ( ) ;
var fetchProduct = m_productRepo . FetchProducts ( ) ;
var fetchUnits = m_productRepo . FetchUnits ( ) ;
var fetchBrands = m_productRepo . FetchBrands ( ) ;
var fetchCategories = m_productRepo . FetchCategories ( ) ;
var fetchRecentSale = m_salesService . FetchRecentTransaction ( 2 5 0 ) ;
// Wait for all tasks to complete
await Task . WhenAll (
fetchCompanyData ,
fetchBranchData ,
fetchProduct ,
fetchUnits ,
fetchBrands ,
fetchCategories ,
fetchRecentSale
) ;
} ) ;
}
}
protected override void OnAfterRender ( bool firstRender )
{
if ( firstRender )
{
CheckPermission ( ) ;
}
base . OnAfterRender ( firstRender ) ;
}
private async Task CheckPermission ( )
{
//Checks if user token is set else redirect user to login page
if ( ! await m_tokenService . IsTokenSet ( ) )
{
m_navigationManager . NavigateTo ( "/login" ) ;
}
else
{
string token = await m_tokenService . GetToken ( ) ;
var authHeader = new AuthenticationHeaderValue ( "Bearer" , token . Substring ( 6 ) . Trim ( ) ) ;
m_http . DefaultRequestHeaders . Authorization = authHeader ;
}
}
async Task OpenReceiptDialog ( )
{
await m_dialogService . OpenSideAsync < ReceiptDialog > ( "Receipt" , options : new SideDialogOptions {
CloseDialogOnOverlayClick = true , Position = DialogPosition . Right , ShowMask = true } ) ;
}
}
}