using Biskilog_Accounting.Client.Pages.Transactions.Elements; using Biskilog_Accounting.Shared.Enums; 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(250); var fetchUsers = m_userService.GetUsers(); var fetchCustomers = m_customerService.GetCustomers(); // Wait for all tasks to complete await Task.WhenAll( fetchCompanyData, fetchBranchData, fetchProduct, fetchUnits, fetchBrands, fetchCategories, fetchRecentSale, fetchUsers ); }); } } 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(); if (m_tokenService.ValidateToken(token) != AuthEnums.Valid) { m_navigationManager.NavigateTo("/login"); } var authHeader = new AuthenticationHeaderValue("Bearer", token.Substring(6).Trim()); m_http.DefaultRequestHeaders.Authorization = authHeader; } } async Task OpenReceiptDialog() { await m_dialogService.OpenSideAsync("Receipt", options: new SideDialogOptions { CloseDialogOnOverlayClick = true, Position = DialogPosition.Right, ShowMask = true }); } private void Click(string a_sender) { m_searchSearch.FireCloseMenus(a_sender); } } }