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.
69 lines
2.5 KiB
69 lines
2.5 KiB
using Biskilog_Accounting.Shared.CustomModels;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
|
|
namespace Biskilog_Accounting.Client.Pages.Dashboard
|
|
{
|
|
public partial class Dashboard
|
|
{
|
|
private TradeSummary m_tradeSummary { get; set; } = new TradeSummary();
|
|
private List<WeeklySaleItem> m_weeklySaleItems { get; set; } = new List<WeeklySaleItem> { };
|
|
private string m_username { get; set; } = string.Empty;
|
|
private bool loadWeeklySales = true;
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
m_username = m_tokenService.GetUserNameFromToken(await m_tokenService.GetToken())!;
|
|
await GetTradeSummary();
|
|
await GetWeeklySales();
|
|
return;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the tade summary
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
async Task GetTradeSummary()
|
|
{
|
|
try
|
|
{
|
|
var response = await m_http.GetAsync("api/analytics/tradesummary");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonContent = await response.Content.ReadAsStringAsync();
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
var tradeSummary = JsonSerializer.Deserialize<TradeSummary>(jsonContent, options);
|
|
m_tradeSummary = tradeSummary;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Gets the tade summary
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
async Task GetWeeklySales()
|
|
{
|
|
try
|
|
{
|
|
var response = await m_http.GetAsync("api/analytics/sales/weekly");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonContent = await response.Content.ReadAsStringAsync();
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
var sales = JsonSerializer.Deserialize<List<WeeklySaleItem>>(jsonContent, options);
|
|
m_weeklySaleItems = sales;
|
|
loadWeeklySales = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|