@page "/GroupManagement"
@using Hushian.Application.Dtos
@using HushianWebApp.Components
@using HushianWebApp.Service
@using HushianWebApp.Services
@inject ILocalStorageService localStorageService;
@inject NavigationManager navigationManager;
@inject GroupService groupService;
@if (context.img?.Length!=0)
{
}
else
{
}
@context.ID
@context.Name
@context.Info
@code {
private ConfirmDialog dialog = default!;
Dictionary parameters = new Dictionary();
Grid grid = default!;
private Modal modal = default!;
string title = "گروه جدید";
public List list = new();
private async Task> DataProvider(GridDataProviderRequest request)
{
if(list.Count <= 0)
list = await groupService.GetGroupsCompany();
int skip = (request.PageNumber - 1) * request.PageSize;
return await Task.FromResult(request.ApplyTo(list != null ? list.Skip(skip).Take(request.PageSize).ToList() : new()));
}
protected override async Task OnInitializedAsync()
{
parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBack));
if (!(await localStorageService.GetItem>("Role")).Any(a => a == "HushianManagerCompany"))
navigationManager.NavigateTo("/NotFound");
await base.OnInitializedAsync();
}
private async Task OnRowClick(GridRowEventArgs args)
{
Dictionary eparameters = new Dictionary();
eparameters.Add("model", args.Item);
eparameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBack));
await modal.ShowAsync($"ویرایش گروه {args.Item.Name}", parameters: eparameters);
}
private async Task SwitchChanged(GroupDto model, bool value)
{
if (model.Available != value)
{
if (await groupService.ChangeAvailableGroupFromManager(model.ID, value))
model.Available = value;
}
}
private async Task DeleteGroup(int GroupID, string name)
{
var confirmation = await dialog.ShowAsync(
title: $"مطمئنی میخوای {name} حذف کنی؟",
message1: "پس از حذف، نمیتوان آن را به حالت اولیه برگرداند.",
message2: "میخوای ادامه بدی؟", new ConfirmDialogOptions()
{
YesButtonColor = ButtonColor.Danger,
YesButtonText = "بله",
NoButtonText = "نه !"
});
if (!confirmation) return;
if (await groupService.DeleteGroupFromManager(GroupID))
{
list = await groupService.GetGroupsCompany();
await grid.RefreshDataAsync();
}
}
async Task CallBack()
{
await modal.HideAsync();
list = await groupService.GetGroupsCompany();
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(int GroupID, string name)
{
Dictionary eparameters = new Dictionary();
eparameters.Add("GroupID", GroupID);
modal.Size = ModalSize.Small;
await modal.ShowAsync($"کارشناسان گروه {name}", parameters: eparameters);
}
}