@page "/users"
Users
@* *@
@* *@ @* *@
@using SeaHavenIndustries.Data.IRepository; @inject IAccountRepository _service; @using Microsoft.JSInterop @using SeaHavenIndustries.Helper.ViewModels @using SeaHavenIndustries.ViewModel @using System.Text.Json @using global::Data.SeaHavenIndustries @inject IJSRuntime JSRuntime @inject NavigationManager Navigation @inject NorthwindService service @using System.Linq.Dynamic.Core @code { RadzenDataGrid grid; int isfirst = 0; int count; string eid; bool issubmitting = false; string submitbtnatrr = ""; private ApplicationUser model = new(); private IEnumerable modelList; private List roles = new List(); bool isLoading = false; // protected override async Task OnParametersSetAsync() // { // // modelList = await _service.GetUsers(); // } async Task Reset() { grid.Reset(true); await grid.FirstPage(true); } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await JSRuntime.InvokeVoidAsync("initScripts"); } } protected async Task savedata() { issubmitting = true; submitbtnatrr = "disabled"; var res = await _service.AddUser(model); if (res == "success") { await ShowSweetAlert("Sucessfully Saved Data", "success"); //await Reset(); issubmitting = false; submitbtnatrr = ""; grid.Reset(); } else { await ShowSweetAlert(res, "error"); issubmitting = false; submitbtnatrr = ""; } } protected async Task Edit(string id) { if (id != "") { eid = id; model = await _service.GetUserById(id); } else { eid = ""; model = new ApplicationUser(); } } private async Task Block(string val) { var result = await JSRuntime.InvokeAsync("Swal.fire", new { html = "
" + "

Are you sure you want to delete

" + "

\"Nicolas Alvarado\"

", type = "warning", showCancelButton = true, customClass = new { confirmButton = "btn btn-success m-1", cancelButton = "btn btn-danger m-1" }, buttonsStyling = false, confirmButtonText = "Yes", cancelButtonText = "No" }); if (result.TryGetProperty("isConfirmed", out var isConfirmedProperty) && isConfirmedProperty.GetBoolean()) { // Call your delete API here var response = await _service.BlockUser(val); if (response == "success") { await JSRuntime.InvokeVoidAsync("Swal.fire", new { icon = "success", title = "Deleted!", text = "User has been Deleted.", type = "primary", showCancelButton = false, customClass = new { confirmButton = "btn btn-success", cancelButton = "btn btn-danger" }, buttonsStyling = false, confirmButtonText = "Ok" }); modelList = await _service.GetUsers(); //await Reset(); await JSRuntime.InvokeVoidAsync("location.reload"); } else { await JSRuntime.InvokeVoidAsync("Swal.fire", new { title = "Not Deleted!", text = "Unsuccessful! Cannot delete this.", type = "danger" }); } } } private async Task ShowSweetAlert(string title, string icon) { // Display a SweetAlert dialog await JSRuntime.InvokeVoidAsync("Swal.fire", new { toast = true, showConfirmButton = false, timer = 3000, title = title, icon = icon, position = "top-end" }); await JSRuntime.InvokeVoidAsync("closemodal"); } async Task LoadData(LoadDataArgs args) { isLoading = true; await Task.Yield(); // This demo is using https://dynamic-linq.net var query = await _service.GetUsersqueryable(); if (!string.IsNullOrEmpty(args.Filter)) { // Filter via the Where method query = query.Where(args.Filter); } if (!string.IsNullOrEmpty(args.OrderBy)) { // Sort via the OrderBy method query = query.OrderBy(args.OrderBy); } // Important!!! Make sure the Count property of RadzenDataGrid is set. count = query.Count(); // Perform paging via Skip and Take. modelList = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); isLoading = false; if (isfirst == 0) { var result = await _service.GetRoles(); if (result != null) { roles = result; } isfirst = 1; } } public void Export(string type) { service.Export("Users", type, new Query() { OrderBy = grid.Query.OrderBy, Filter = grid.Query.Filter, Select = string.Join(",", grid.ColumnsCollection.Where(c => c.GetVisible() && !string.IsNullOrEmpty(c.Property)) .Select(c => c.Property.Contains(".") ? $"{c.Property} as {c.Property.Replace(".", "_")}" : c.Property)) }); } }