155 lines
6.3 KiB
Plaintext
155 lines
6.3 KiB
Plaintext
@page "/UserManagement"
|
||
<ConfirmDialog @ref="dialog" />
|
||
@using Common.Dtos.User
|
||
@using Hushian.Application.Dtos
|
||
@using HushianWebApp.Components
|
||
@using HushianWebApp.Service
|
||
@using HushianWebApp.Services
|
||
@inject ILocalStorageService localStorageService;
|
||
@inject NavigationManager navigationManager;
|
||
@inject UserService userService;
|
||
<Modal @ref="modal" />
|
||
|
||
<Button Color="ButtonColor.Success" Style="margin-bottom:10px"
|
||
@onclick="async()=>{
|
||
await modal.ShowAsync<ADDExperComponent>(title,parameters:parameters);
|
||
}">
|
||
کارشناس جدید
|
||
</Button>
|
||
|
||
<Grid @ref="grid" TItem="HushianUserDto"
|
||
AllowSorting="true"
|
||
Class="table table-hover"
|
||
DataProvider="DataProvider"
|
||
HeaderRowCssClass="bg-primary text-white bg-opacity-75 border-bottom-0"
|
||
Responsive="true"
|
||
AllowPaging="true"
|
||
OnRowDoubleClick="OnRowClick"
|
||
AllowRowClick=true>
|
||
|
||
<GridColumns>
|
||
<GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="تصویر کاربر" >
|
||
@if (context.img?.Length != 0)
|
||
{
|
||
<Image Class="rounded-circle mx-auto d-block" src="@GetImageSource(context.img)" height="25" width="25" alt="Uploaded Image" />
|
||
}
|
||
else
|
||
{
|
||
<Icon Name="IconName.Person" Size="IconSize.x5" />
|
||
}
|
||
</GridColumn>
|
||
<GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="نام کاریری" SortKeySelector="item => item.UserName">
|
||
@context.UserName
|
||
</GridColumn>
|
||
|
||
<GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="نام کامل" SortKeySelector="item => item.FullName">
|
||
@context.FullName
|
||
</GridColumn>
|
||
|
||
<GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="پست اکترونیک" SortKeySelector="item => item.Email">
|
||
@context.Email
|
||
</GridColumn>
|
||
|
||
@* <GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="موبابل" SortKeySelector="item => item.PhoneNumber">
|
||
@context.PhoneNumber
|
||
</GridColumn> *@
|
||
|
||
<GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="وضعیت">
|
||
<Switch Value="@context.Available" ValueExpression="() => context.Available" ValueChanged="async(v)=>await SwitchChanged(context,v)" />
|
||
|
||
</GridColumn>
|
||
<GridColumn HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center" TItem="HushianUserDto" HeaderText="عملیات">
|
||
<Button Color="ButtonColor.Danger" Size="ButtonSize.ExtraSmall" @onclick="async()=>await DeleteExper(context.UserID,context.FullName)"> حذف </Button>
|
||
<Button Color="ButtonColor.Warning" Size="ButtonSize.ExtraSmall" @onclick="async()=>await showGroupsComponent(context.UserID,context.FullName)"> گروه ها </Button>
|
||
|
||
</GridColumn>
|
||
</GridColumns>
|
||
|
||
</Grid>
|
||
|
||
@code {
|
||
private ConfirmDialog dialog = default!;
|
||
|
||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||
Grid<HushianUserDto> grid = default!;
|
||
private Modal modal = default!;
|
||
string title = "کارشناس جدید";
|
||
protected override async Task OnInitializedAsync()
|
||
{
|
||
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBack));
|
||
|
||
if (!(await localStorageService.GetItem<List<string>>("Role")).Any(a =>a== "HushianManagerCompany") )
|
||
navigationManager.NavigateTo("/NotFound");
|
||
await base.OnInitializedAsync();
|
||
}
|
||
private async Task<GridDataProviderResult<HushianUserDto>> DataProvider(GridDataProviderRequest<HushianUserDto> request)
|
||
{
|
||
var employees = await userService.GetExpersCompany(0, request.PageNumber, request.PageSize);
|
||
return await Task.FromResult(request.ApplyTo(employees != null ? employees.list : new()));
|
||
}
|
||
async Task CallBack()
|
||
{
|
||
await modal.HideAsync();
|
||
await grid.RefreshDataAsync();
|
||
}
|
||
private async Task OnRowClick(GridRowEventArgs<HushianUserDto> args)
|
||
{
|
||
var editmodel = new EditUserFromUserDto()
|
||
{
|
||
Email = args.Item.Email,
|
||
FullName = args.Item.FullName,
|
||
UserName = args.Item.UserName,
|
||
img = args.Item.img
|
||
};
|
||
Dictionary<string, object> eparameters = new Dictionary<string, object>();
|
||
eparameters.Add("model", editmodel);
|
||
eparameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBack));
|
||
|
||
await modal.ShowAsync<UpdateExperComponent>($"ویرایش کارشناس {args.Item.FullName}", parameters: eparameters);
|
||
|
||
}
|
||
private async Task SwitchChanged(HushianUserDto model,bool value)
|
||
{
|
||
if (model.Available != value)
|
||
{
|
||
if (await userService.ChangeAvailableExperFromManager(model.UserID, value))
|
||
model.Available = value;
|
||
}
|
||
|
||
|
||
}
|
||
private async Task DeleteExper(string ExperID,string name)
|
||
{
|
||
var confirmation = await dialog.ShowAsync(
|
||
title: $"مطمئنی میخوای {name} حذف کنی؟",
|
||
message1: "پس از حذف، نمیتوان آن را به حالت اولیه برگرداند.",
|
||
message2: "میخوای ادامه بدی؟",new ConfirmDialogOptions()
|
||
{
|
||
YesButtonColor=ButtonColor.Danger,
|
||
YesButtonText="بله",
|
||
NoButtonText="نه !"
|
||
});
|
||
|
||
if (!confirmation) return;
|
||
|
||
|
||
if (await userService.DeleteExperFromManager(ExperID))
|
||
await grid.RefreshDataAsync();
|
||
}
|
||
private string GetImageSource(byte[]? img)
|
||
{
|
||
if (img != null)
|
||
{
|
||
return $"data:image/jpeg;base64,{Convert.ToBase64String(img)}";
|
||
}
|
||
return string.Empty;
|
||
}
|
||
async Task showGroupsComponent(string ExperID, string name)
|
||
{
|
||
Dictionary<string, object> eparameters = new Dictionary<string, object>();
|
||
eparameters.Add("ExperID", ExperID);
|
||
|
||
modal.Size = ModalSize.Small;
|
||
await modal.ShowAsync<UserGroupsComponent>($"گروه های کارشناس {name}", parameters: eparameters);
|
||
}
|
||
} |