New source control repo for Biskilog POS - secure hub to store & manage source code. Streamlines dev process, tracks changes, & improves collaboration. Ensures reliable software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.6 KiB

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(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();
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
});
}
}
}