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 m_weeklySaleItems { get; set; } = new List { }; 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; } /// /// Gets the tade summary /// /// 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(jsonContent, options); m_tradeSummary = tradeSummary; StateHasChanged(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } /// /// Gets the tade summary /// /// 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>(jsonContent, options); m_weeklySaleItems = sales; loadWeeklySales = false; StateHasChanged(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }