using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using HyperCube.Models; namespace HyperCube.Pages { public partial class Wallet { [Inject] public AppData AppData { get; set; } private AccountModel account = new(); string myBalance = ""; protected override async Task OnInitializedAsync() { account = AppData.CurrentAccount; if (Blockchain.GetMain() != null) myBalance = await account.GetBalance(); } bool admin { get { return account.Roles.Contains(Role.Admin); } set { if (!account.Roles.Contains(Role.Admin)) { account.AddRole(Role.Admin); InsertRole(Role.Admin); } else { account.RemoveRole(Role.Admin); DeleteRole(Role.Admin); } } } bool initiator { get { return account.Roles.Contains(Role.Initiator); } set { if (!account.Roles.Contains(Role.Initiator)) { account.AddRole(Role.Initiator); InsertRole(Role.Initiator); } else { account.RemoveRole(Role.Initiator); DeleteRole(Role.Initiator); } } } bool verifier { get { return account.Roles.Contains(Role.Verifier); } set { if (!account.Roles.Contains(Role.Verifier)) { account.AddRole(Role.Verifier); InsertRole(Role.Verifier); } else { account.RemoveRole(Role.Verifier); DeleteRole(Role.Verifier); } } } bool requester { get { return account.Roles.Contains(Role.Requester); } set { if (!account.Roles.Contains(Role.Requester)) { account.AddRole(Role.Requester); InsertRole(Role.Requester); } else { account.RemoveRole(Role.Requester); DeleteRole(Role.Requester); } } } private async Task InsertRole(Role role) { await MySQLConnector.Instance().SQLInsert($"insert into account_roles (account_uuid, role_id) values ('{account.UUID}', {(int)role})"); } private async Task DeleteRole(Role role) { await MySQLConnector.Instance().SQLInsert($"delete from account_roles where account_uuid = '{account.UUID}' and role_id={(int)role}"); } } }