This commit is contained in:
mmrbnjd
2025-07-12 21:33:44 +03:30
parent d397f70b9a
commit 8a6ff3da67
32 changed files with 320 additions and 403 deletions

View File

@@ -1,4 +1,5 @@
@using Common.Dtos.User
@using Common.Dtos.Exper
@using Common.Validation
@using HushianWebApp.Service
@using HushianWebApp.Services
@inject UserService userService;
@@ -10,48 +11,29 @@
<input dir="ltr" style="text-align:center;margin-bottom:10px" @bind-value="@model.FullName" type="text" class="form-control" placeholder="نام کامل" />
</div>
<div class="col-md-12">
<input dir="ltr" style="text-align:center;margin-bottom:10px" @bind-value="@model.Email" type="text" class="form-control" placeholder="پست الکترونیک" />
</div>
<div class="col-md-12" style="display: flex;flex-wrap: nowrap;align-items: baseline;">
<InputFile type="file" OnChange="OnFileChange" accept=".png" style="margin-bottom:10px" />
@if (model.img != null && model.img.Length > 0)
{
<Image src="@GetImageSource()" Class="rounded mx-auto d-block" height="25" width="25" alt="Uploaded Image" />
}
</div>
<Button Loading=loading LoadingText="در حال ذخیره اطلاعات..." Color="ButtonColor.Warning" @onclick="NewItem"> ویرایش </Button>
@if (isAuthorizedCompanyUser)
{
<Button Loading=loading LoadingText="در حال آزادسازی..." Color="ButtonColor.Danger" @onclick="FreeExper"> آزادسازی کارشناس </Button>
}
</div>
@code {
bool isAuthorizedCompanyUser = false;
[Parameter] public EventCallback<EditUserFromUserDto> OnMultipleOfThree { get; set; }
public List<string> Roles { get; set; } = new();
[Parameter] public EventCallback<Update_ExperDto> OnMultipleOfThree { get; set; }
public string Role { get; set; }
public bool loading { get; set; } = false;
[Inject] protected ToastService ToastService { get; set; } = default!;
public EditUserFromUserDto model { get; set; } = new();
public Update_ExperDto model { get; set; } = new();
protected override async Task OnInitializedAsync()
{
var user=await userService.GetCurrentUser();
if (user!=null)
{
model.UserName=user.UserName;
model.img = user.img;
model.FullName = user.FullName;
model.Email = user.Email;
Roles = await localStorageService.GetItem<List<string>>("Role");
isAuthorizedCompanyUser = Roles.Contains("HushianExperCompany") && await userService.CheckAvailableExperInCompany();
Role = await localStorageService.GetItem<string>("Role");
isAuthorizedCompanyUser = Role=="Exper" && await userService.CheckAvailableExperInCompany();
}
else
{
@@ -59,30 +41,16 @@
}
await base.OnInitializedAsync();
}
private async Task OnFileChange(InputFileChangeEventArgs e)
{
var file = e.File;
using (var memoryStream = new MemoryStream())
{
await file.OpenReadStream().CopyToAsync(memoryStream);
model.img = memoryStream.ToArray();
}
}
private string GetImageSource()
{
if (model.img != null)
{
return $"data:image/jpeg;base64,{Convert.ToBase64String(model.img)}";
}
return string.Empty;
}
async Task NewItem()
{
if (!string.IsNullOrEmpty(model.FullName))
{
if (string.IsNullOrEmpty(model.Email)) model.Email = $"{model.UserName}@hushian.ir";
if (!model.FullName.IsOnlyPersianLetters())
{
ToastService.Notify(new(ToastType.Danger, $"نام و نام خانوادگی را به صورت فارسی مشخص کنید"));
return;
}
loading = true;
if (await userService.EditUserYourself(model))
{
@@ -92,15 +60,5 @@
loading = false;
}
}
async Task FreeExper()
{
loading = true;
if (await userService.FreeExper())
{
loading = false;
await OnMultipleOfThree.InvokeAsync(model);
}
loading = false;
}
}