using System.ComponentModel; using AdminPanel.Models; using AdminPanel.Services; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using MudBlazor; namespace AdminPanel.Pages { public partial class UserListPanel { [Inject] public ISnackbar Snackbar { get; private init; } [Inject] public IUsersService Service { get; private init; } private HashSet SelectedItems { get; set; } = new(); private string? FormAccountName { get; set; } private string? FormAccountEmail { get; set; } private string? FormAccountPassword { get; set; } private bool FormAccountIsAdmin { get; set; } public bool IsAddingUser { get; set; } private async Task> LoadUsersFromServer(GridState state) { var (count, users) = await Service.ListUsers((uint)(state.Page * state.PageSize), (uint)state.PageSize); return new GridData { TotalItems = (int)count, Items = users }; } private async void OnAccountEdited(User user) { Console.WriteLine(user.IsAdmin); try { await Service.UpdateUser(user); } catch (Exception) { Snackbar.Add("Server responded with errors, your given input may be incorrect.\nIf you entered a new email, verify that the email is not used by another member."); } } private async void ConfirmAddAccount(MouseEventArgs e) { // We no longer add an account if it is confirmed IsAddingUser = false; try { await Service.AddUser(FormAccountName!, FormAccountEmail!, FormAccountPassword!, FormAccountIsAdmin); StateHasChanged(); } catch (Exception) { Snackbar.Add("Server responded with errors, your given input may be incorrect."); } } private async void RemoveSelection(MouseEventArgs e) { var items = SelectedItems.ToList().ConvertAll(u => u.Id); Console.WriteLine(items.Count); try { await Service.RemoveUsers(items); } catch (Exception) { Snackbar.Add("Server responded with errors"); } } } }