Files
Hushian/Presentation/HushianWebApp/Components/UpdateExperComponent.razor
mmrbnjd ff342a53c0 ...
2025-07-11 20:37:28 +03:30

73 lines
2.3 KiB
Plaintext

@using Common.Dtos.User
@using Hushian.Application.Dtos
@using HushianWebApp.Service
@using HushianWebApp.Services
@inject UserService userService;
<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>
</div>
@code {
[Parameter] public EditUserFromUserDto model { get; set; }
[Parameter] public EventCallback OnMultipleOfThree { get; set; }
public bool loading { get; set; } = false;
}
@functions{
async Task NewItem()
{
if (!string.IsNullOrEmpty(model.FullName))
{
if (string.IsNullOrEmpty(model.Email)) model.Email = $"{model.UserName}@hushian.ir";
loading = true;
if (await userService.ExperEditingFromManager(model))
{
loading = false;
await OnMultipleOfThree.InvokeAsync();
}
loading = false;
}
}
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;
}
}