107 lines
3.6 KiB
Plaintext
107 lines
3.6 KiB
Plaintext
![]() |
@using Common.Dtos.User
|
||
|
@using HushianWebApp.Service
|
||
|
@using HushianWebApp.Services
|
||
|
@inject UserService userService;
|
||
|
@inject ILocalStorageService localStorageService;
|
||
|
<div class="row" style="height: fit-content; padding: 1rem;">
|
||
|
|
||
|
|
||
|
<div class="col-md-12">
|
||
|
|
||
|
<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();
|
||
|
public bool loading { get; set; } = false;
|
||
|
[Inject] protected ToastService ToastService { get; set; } = default!;
|
||
|
public EditUserFromUserDto 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();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ToastService.Notify(new ToastMessage(ToastType.Danger,"خطا در فراخوانی اطلاعات کاربر"));
|
||
|
}
|
||
|
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";
|
||
|
|
||
|
loading = true;
|
||
|
if (await userService.EditUserYourself(model))
|
||
|
{
|
||
|
loading = false;
|
||
|
await OnMultipleOfThree.InvokeAsync(model);
|
||
|
}
|
||
|
loading = false;
|
||
|
}
|
||
|
}
|
||
|
async Task FreeExper()
|
||
|
{
|
||
|
loading = true;
|
||
|
if (await userService.FreeExper())
|
||
|
{
|
||
|
loading = false;
|
||
|
await OnMultipleOfThree.InvokeAsync(model);
|
||
|
}
|
||
|
loading = false;
|
||
|
}
|
||
|
|
||
|
}
|