Benjamin Arhen
2 years ago
25 changed files with 413 additions and 184 deletions
@ -0,0 +1,24 @@ |
|||||
|
using System.Net.Http.Headers; |
||||
|
|
||||
|
namespace Biskilog_Accounting.Client.Layouts |
||||
|
{ |
||||
|
public partial class MainLayout |
||||
|
{ |
||||
|
|
||||
|
protected override async Task OnInitializedAsync() |
||||
|
{ |
||||
|
//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; |
||||
|
} |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -1,7 +1,112 @@ |
|||||
namespace Biskilog_Accounting.Client.Pages.Auth |
using Microsoft.AspNetCore.Components.Web; |
||||
|
using Microsoft.AspNetCore.Components; |
||||
|
using System.Net.Http.Headers; |
||||
|
using Biskilog_Accounting.Shared.ClientContractModels; |
||||
|
using Biskilog_Accounting.Shared.Interfaces; |
||||
|
using System.Net.Http.Json; |
||||
|
|
||||
|
namespace Biskilog_Accounting.Client.Pages.Auth |
||||
{ |
{ |
||||
public partial class Login |
public partial class Login |
||||
{ |
{ |
||||
|
private string m_email, m_password; |
||||
|
private bool m_remember { get; set; } |
||||
|
protected bool IsVisible { get; set; } |
||||
|
//NotificationMessage notificationMessage = new NotificationMessage();
|
||||
|
private Userauth authenticatedUser; |
||||
|
/// <summary>
|
||||
|
/// Handles the click or press event of the enter key
|
||||
|
/// </summary>
|
||||
|
/// <param name="e"></param>
|
||||
|
public async void Enter(KeyboardEventArgs e) |
||||
|
{ |
||||
|
if (e.Code == "Enter" || e.Code == "NumpadEnter") |
||||
|
{ |
||||
|
await pagaAuth(); |
||||
|
} |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Authenticates the user and determines the type of page layout to show
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
async Task pagaAuth() |
||||
|
{ |
||||
|
|
||||
|
ShowSpinner(); |
||||
|
try |
||||
|
{ |
||||
|
authenticatedUser = new Userauth |
||||
|
{ |
||||
|
UserId = 0, |
||||
|
Username = m_email, |
||||
|
Email = m_email, |
||||
|
Passsword = m_password |
||||
|
}; |
||||
|
var responseMain = await m_http.PostAsJsonAsync("api/authentication/type-a", authenticatedUser); |
||||
|
if (responseMain.IsSuccessStatusCode) |
||||
|
{ |
||||
|
string token = await responseMain.Content.ReadAsStringAsync(); |
||||
|
await m_tokenService.SetToken(token, m_remember); |
||||
|
|
||||
|
var authHeader = new AuthenticationHeaderValue("Bearer", token); |
||||
|
m_http.DefaultRequestHeaders.Authorization = authHeader; |
||||
|
|
||||
|
m_navigationManager.NavigateTo("/"); |
||||
|
} |
||||
|
else if (responseMain.StatusCode == System.Net.HttpStatusCode.BadRequest) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Console.WriteLine(ex.ToString()); |
||||
|
} |
||||
|
HideSpinner(); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Shows the loading spinner
|
||||
|
/// </summary>
|
||||
|
public void ShowSpinner() |
||||
|
{ |
||||
|
IsVisible = true; |
||||
|
StateHasChanged(); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Hides the loading spinner
|
||||
|
/// </summary>
|
||||
|
public void HideSpinner() |
||||
|
{ |
||||
|
IsVisible = false; |
||||
|
StateHasChanged(); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Shows a notification message
|
||||
|
/// </summary>
|
||||
|
/// <param name="message"></param>
|
||||
|
/// <returns></returns>
|
||||
|
//async Task ShowNotification(NotificationMessage message)
|
||||
|
//{
|
||||
|
// notificationService.Notify(message);
|
||||
|
|
||||
|
// await InvokeAsync(() => { StateHasChanged(); });
|
||||
|
//}
|
||||
|
/// <summary>
|
||||
|
/// Sets the username value
|
||||
|
/// </summary>
|
||||
|
/// <param name="value"></param>
|
||||
|
void usernameInput(string value) |
||||
|
{ |
||||
|
m_email = value; |
||||
|
StateHasChanged(); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Sets the password value
|
||||
|
/// </summary>
|
||||
|
/// <param name="value"></param>
|
||||
|
void passwordInput(string value) |
||||
|
{ |
||||
|
m_password = value; |
||||
|
StateHasChanged(); |
||||
|
} |
||||
} |
} |
||||
} |
} |
@ -1,19 +1,41 @@ |
|||||
using Biskilog_Accounting.Shared.Interfaces; |
using Biskilog_Accounting.Shared.CustomModels; |
||||
|
using System.Net.Http.Json; |
||||
|
using System.Text.Json; |
||||
|
|
||||
namespace Biskilog_Accounting.Client.Pages.Dashboard |
namespace Biskilog_Accounting.Client.Pages.Dashboard |
||||
{ |
{ |
||||
public partial class Dashboard |
public partial class Dashboard |
||||
{ |
{ |
||||
private readonly ITokenService m_tokenService; |
private TradeSummary m_tradeSummary { get; set; } = new TradeSummary(); |
||||
private double CurrentTradeSale = 7000; |
private string m_username { get; set; } = string.Empty; |
||||
private double PreviousTradeSale = 2000.80; |
protected override async Task OnInitializedAsync() |
||||
private string username { get; set; } |
|
||||
public Dashboard() { } |
|
||||
public Dashboard(ITokenService a_tokenService) => m_tokenService = a_tokenService; |
|
||||
protected override void OnInitialized() |
|
||||
{ |
{ |
||||
username = "username"; |
m_username = m_tokenService.GetUserNameFromToken(await m_tokenService.GetToken())!; |
||||
base.OnInitialized(); |
await GetSummary(); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the tade summary
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
async Task GetSummary() |
||||
|
{ |
||||
|
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); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,28 @@ |
|||||
|
<div class="card"> |
||||
|
<div class="card-body"> |
||||
|
<div class="card-title d-flex align-items-start justify-content-between"> |
||||
|
<div class="avatar flex-shrink-0"> |
||||
|
<img src="@Icon" |
||||
|
alt="chart success" |
||||
|
class="rounded" /> |
||||
|
</div> |
||||
|
<div class="dropdown"> |
||||
|
<button class="btn p-0" |
||||
|
type="button" |
||||
|
id="cardOpt3" |
||||
|
data-bs-toggle="dropdown" |
||||
|
aria-haspopup="true" |
||||
|
aria-expanded="false"> |
||||
|
<i class="bx bx-dots-vertical-rounded"></i> |
||||
|
</button> |
||||
|
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="cardOpt3"> |
||||
|
<a class="dropdown-item" href="javascript:void(0);">View More</a> |
||||
|
<a class="dropdown-item" href="javascript:void(0);">Delete</a> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<span class="fw-semibold d-block mb-1">@Title</span> |
||||
|
<h3 class="card-title mb-2">@Value</h3> |
||||
|
<small class="@(Percentage > 0 ? "text-success" : Percentage == 0 ? "bx-forward-arrow-alt" : "text-danger") fw-semibold"><i class="bx @(Percentage > 0 ? "bx-up-arrow-alt" : Percentage == 0 ? "bx-forward-arrow-alt" : "bx-down-arrow-alt")"></i> @Percentage %</small> |
||||
|
</div> |
||||
|
</div> |
@ -0,0 +1,16 @@ |
|||||
|
using Microsoft.AspNetCore.Components; |
||||
|
|
||||
|
namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements |
||||
|
{ |
||||
|
public partial class AnalyticsItemSmall |
||||
|
{ |
||||
|
[Parameter] |
||||
|
public string Icon { get; set; } = string.Empty; |
||||
|
[Parameter] |
||||
|
public string Title { get; set; }= string.Empty; |
||||
|
[Parameter] |
||||
|
public double Value{ get; set; } |
||||
|
[Parameter] |
||||
|
public double Percentage { get;set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Biskilog_Accounting.Shared.CustomModels |
||||
|
{ |
||||
|
public class TradeSummary |
||||
|
{ |
||||
|
public DateTime CurrentTradeDate { get; set; } = DateTime.Now; |
||||
|
public DateTime LastTradeDate { get; set; } = DateTime.Now.AddDays(-1); |
||||
|
public double CurrentTradeSales { get; set; } = 0; |
||||
|
public double LastTradeSales { get; set; } = 0; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue