using Blazorise.DataGrid; using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Server.Data.Service; using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Pages { /// /// The users class (a. beging, 01.04.2022) /// public partial class Users { #region Dependencies (Injected) //////////////////////////////////////////////////////////////////////////////////////////////////// /// Gets or sets the user service. /// /// The user service. //////////////////////////////////////////////////////////////////////////////////////////////////// [Inject] public UserService UserService { get; set; } = null!; #endregion #region Public Properties /// /// Gets or sets the value of the user data grid (ab) /// public DataGrid UserDataGrid { get; set; } #endregion #region Private Properties /// /// Gets or sets the value of the user list (ab) /// private List? UserList { get; set; } public User? SelectedUser { get; set; } public IEnumerable UserGroups => Enum.GetValues(); public List Companies { get; set; } public List SelectedCompanies { get; set; } public List SelectedCompanyTexts { get; set; } = new(); #endregion #region Override OnAfterRenderAsync /// /// Ons the after render using the specified first render (a. beging, 01.04.2022) /// /// The first render protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) await LoadUsers(); await base.OnAfterRenderAsync(firstRender); } #endregion protected override void OnInitialized() { Companies = new List { new Company{Name = "Germany", ISO = "DE"}, new Company{Name = "USA", ISO = "US"}, new Company{Name = "England", ISO = "GB"}, new Company{Name = "Austria", ISO = "AT"} }; SelectedCompanies = new List {UserGroups.ElementAt(2)}; base.OnInitialized(); } #region Private Method Chang /// /// Changs the context (a. beging, 01.04.2022) /// /// The context /// The type private void Chang(CellEditContext context, UserType type) { context.Item.Type = type; } #endregion #region Private Method LoadUsers /// /// Loads the users (a. beging, 01.04.2022) /// private async Task LoadUsers() { var usersR = await UserService.GetUsersAsync(); if (usersR.Success) UserList = usersR.Data; await InvokeAsync(StateHasChanged); } #endregion #region Private Method RowInserted /// /// Rows the inserted using the specified arg (a. beging, 01.04.2022) /// /// The arg private async Task RowInserted(SavedRowItem> arg) { var addUserR = await UserService.AddUserAsync(arg.Item); if (!addUserR.Success) { //Todo Error Toast [01.04.22 - Andre Beging] } else { await LoadUsers(); } } #endregion #region Private Method RowUpdated /// /// Rows the updated using the specified arg (a. beging, 01.04.2022) /// /// The arg private async Task RowUpdated(SavedRowItem> arg) { if (arg.Item?.Id == null || arg.Item.Id.Equals(Guid.Empty) || arg.Values?.Any() != true) return; var result = await UserService.Update(arg.Item); } #endregion private async Task SelectedChanged(List arg) { } } public class Company { public string Name { get; set; } public string ISO { get; set; } } }