/
onimor
/
ASWRemoteViewerRev
Обзор
Документация
Войти
/
onimor
/
ASWRemoteViewerRev
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
RemoteViewing/ASW.RemoteViewing/ASW.RemoteViewing.Client/Features/PlaceUser/Components/EditPlaceUser.razor
118 строк
4 KB
onimor
Добавьте файлы проекта.
28 авг 2025, 13:00
28 авг 2025, 13:00
855ae9a
Код
Авторство
О чём код?
@inherits UiComponentBase @inject IDialogService DialogService @inject PlaceUserClient PlaceUserClient <MudDialog> <TitleContent> <MudText Typo="Typo.h6" Class="mb-2">Токен</MudText> </TitleContent> <DialogContent> <MudStack> <MudTextField @bind-Value="_name" Label="Наименование" /> </MudStack> </DialogContent> <DialogActions> <MudButton OnClick="Cancel">Отмена</MudButton> @if (Processing) { <MudStack Class="pa-2"> <MudProgressCircular Color="Color.Info" Class="ms-n1" Size="Size.Small" Indeterminate="true" /> </MudStack> } else { <MudButton Disabled="@Processing" Color="Color.Error" OnClick="DeleteAsync"> Удалить </MudButton> <MudButton Disabled="@Processing" Color="Color.Warning" OnClick="UpdateKeyAsync"> Перевыпустить </MudButton> <MudButton Disabled="@Processing" Color="Color.Success" OnClick="UpdateAsync"> Сохранить </MudButton> } </DialogActions> </MudDialog> @code { [CascadingParameter] IMudDialogInstance? MudDialog { get; set; } [Parameter] public required PlaceUserDto PlaceUser { get; set; } private string? _name = string.Empty; private DialogOptions _dialogOptionsSmall = new() { CloseButton = true, FullWidth = true, MaxWidth = MaxWidth.Small, CloseOnEscapeKey = false, BackdropClick = false }; private DialogOptions _dialogOptionsExSmall = new() { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; protected override void OnParametersSet() { if (PlaceUser is null) { ShowError("Не удалось открыть"); Cancel(); } _name = PlaceUser?.Name; } private async Task UpdateAsync() { await RunSafe(async () => { if (string.IsNullOrEmpty(_name)) throw new ValidationException("Наименование не может быть пустым"); await PlaceUserClient.UpdateAsync(PlaceUser.Id, new UpdatePlaceUserRequest { Name = _name }); MudDialog?.Close(); }, showProcessing: true); } private async Task DeleteAsync() { await RunSafe(async () => { var parameters = new DialogParameters { ["ContentText"] = "Вы уверены, что хотите удалить токен?", ["ButtonText"] = "Удалить", ["Color"] = Color.Error }; var dialog = await DialogService.ShowAsync<WarningDialog>("Удаление", parameters, _dialogOptionsExSmall); var result = await dialog.Result; if (result?.Canceled == false) { await PlaceUserClient.DeleteAsync(PlaceUser.Id); MudDialog?.Close(); } }, showProcessing: true); } private async Task UpdateKeyAsync() { await RunSafe(async () => { var parameters = new DialogParameters { ["ContentText"] = "Вы уверены, что хотите перевыпустить токен?", ["ButtonText"] = "Перевыпустить", ["Color"] = Color.Warning }; var dialog = await DialogService.ShowAsync<WarningDialog>("Перевыпуск", parameters, _dialogOptionsExSmall); var result = await dialog.Result; if (result?.Canceled == false) { var updateResult = await PlaceUserClient.UpdateKeyAsync(PlaceUser.Id); var viewTokenParameters = new DialogParameters { ["Token"] = updateResult?.Token, }; MudDialog?.Close(); await DialogService.ShowAsync<ViewPlaceUserToken>("Токен доступа", viewTokenParameters, _dialogOptionsSmall); } }, showProcessing: true); } private void Cancel() => MudDialog?.Cancel(); }