mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 23:33:10 +00:00
301 lines
13 KiB
Text
301 lines
13 KiB
Text
@page "/users"
|
|
<Header pagename="Users " icon='<i class="material-icons-round opacity-10">person</i>'></Header>
|
|
|
|
<div class="row mt-3">
|
|
<div class="col-12">
|
|
<div class="card cardbg">
|
|
<!-- Card header -->
|
|
<div class="card-header pb-0 cardbg">
|
|
<div class="d-lg-flex">
|
|
<div>
|
|
<h5 class="mb-0 ps-3">Users</h5>
|
|
</div>
|
|
<div class="ms-auto my-auto mt-lg-0 mt-4">
|
|
|
|
<div class="ms-auto my-auto d-flex flex-wrap justify-content-end text-end">
|
|
@* <RadzenButton Text="Export XLS" Icon="grid_on" Click="@(args => Export("excel"))" class="mb-0 me-2" /><RadzenButton Text="Export CSV" Icon="wrap_text" Click="@(args => Export("csv"))" class="mb-0 me-2" />
|
|
*@
|
|
<button class="btn bg-gradient-info btn-sm mb-0" @onclick='()=>Edit("")' data-bs-toggle="modal" data-bs-target="#exampleModal">+ New User</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<RadzenDataGrid style="height: auto" @ref="grid" PagerAlwaysVisible="true" IsLoading=@isLoading ShowPagingSummary="true" Count="@count" Data="@modelList" LoadData="@LoadData" AllowSorting="true" AllowFiltering="true" AllowPaging="true" PageSize="10" PagerHorizontalAlign="HorizontalAlign.Right" TItem="UserRoleViewModel" ColumnWidth="200px">
|
|
<Columns>
|
|
<RadzenDataGridColumn TItem="UserRoleViewModel" Property="UserName" Title="Name" Width="120px" />
|
|
@* <RadzenDataGridColumn TItem="UserRoleViewModel" Property="Email" Title="Email" Width="120px" /> *@
|
|
<RadzenDataGridColumn TItem="UserRoleViewModel" Property="RoleName" Title="Role" Width="120px" />
|
|
@* <RadzenDataGridColumn TItem="UserRoleViewModel" Property="Status" Title="Status" Width="120px" /> *@
|
|
<RadzenDataGridColumn TItem="UserRoleViewModel" Property="Date" Title="Date Added" Width="120px" />
|
|
|
|
<RadzenDataGridColumn TItem="UserRoleViewModel" Title="Action" Context="employee" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="156px">
|
|
<Template Context="modelList">
|
|
<RadzenButton Icon="edit" data-bs-target="#exampleModal" data-bs-toggle="modal" ButtonStyle="ButtonStyle.Success" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
|
Click="@(args => Edit(modelList.Id))" @onclick:stopPropagation="true">
|
|
</RadzenButton>
|
|
<RadzenButton Icon="delete" ButtonStyle="ButtonStyle.Danger" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
|
Click="@(args => Block(modelList.Id))" @onclick:stopPropagation="true">
|
|
</RadzenButton>
|
|
</Template>
|
|
</RadzenDataGridColumn>
|
|
</Columns>
|
|
</RadzenDataGrid>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered " role="document">
|
|
<div class="modal-content cardbg">
|
|
<div class="modal-header">
|
|
@if (string.IsNullOrEmpty(eid))
|
|
{
|
|
<h5 class="modal-title font-weight-normal" id="exampleModalLabel">Add New User</h5>
|
|
}
|
|
else
|
|
{
|
|
<h5 class="modal-title font-weight-normal" id="exampleModalLabel">Edit User</h5>
|
|
}
|
|
<button type="button" class="btn-close text-dark" data-bs-dismiss="modal" aria-label="Close"> X
|
|
</button>
|
|
</div>
|
|
<form method="post" @onsubmit="savedata">
|
|
<div class="modal-body">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<label for="exampleFormControlInput1" class="form-label">Name:</label>
|
|
<div class="input-group input-group-outline mt-1 mb-2">
|
|
<input type="text" @bind="model.FirstName" class="form-control" />
|
|
</div>
|
|
</div>
|
|
<div class="col-12">
|
|
<label for="exampleFormControlInput1" class="form-label">Email:</label>
|
|
<div class="input-group input-group-outline mt-1 mb-2">
|
|
<input type="email" @bind="model.Email" class="form-control" />
|
|
</div>
|
|
</div>
|
|
<div class="col-12">
|
|
<label for="exampleFormControlInput1" class="form-label">Role:</label>
|
|
<div class="input-group input-group-outline mt-1 mb-2">
|
|
<select id="customFieldName" class="form-select input-group mb-0" @bind="model.PhoneNumber" style="width: 280px;border: 1px solid;border-radius: 5px;padding-inline: 15px;" aria-label="Default select example">
|
|
<option value="0">Select Role</option>
|
|
@if (roles != null)
|
|
{
|
|
foreach (var role in roles)
|
|
{
|
|
<option value="@role.RoleName">@role.RoleName</option>
|
|
}
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" class="btn bg-gradient-info @submitbtnatrr">Add</button>
|
|
@if (issubmitting)
|
|
{
|
|
<img src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==">
|
|
}
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@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<UserRoleViewModel> grid;
|
|
int isfirst = 0;
|
|
int count;
|
|
string eid;
|
|
bool issubmitting = false;
|
|
string submitbtnatrr = "";
|
|
private ApplicationUser model = new();
|
|
private IEnumerable<UserRoleViewModel> modelList;
|
|
private List<RolesViewModel> roles = new List<RolesViewModel>();
|
|
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<JsonElement>("Swal.fire", new
|
|
{
|
|
html = "<div style='text-align: center;'><img src='./assets/img/delete icon.png' style='width: 100px;' /></div>" +
|
|
"<h4>Are you sure you want to delete</h4>" +
|
|
"<p style='font-size: 18px;'>\"Nicolas Alvarado\"</p>",
|
|
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))
|
|
});
|
|
}
|
|
}
|