@page "/session/edit/{SessionId:guid}" @using GmRelay.Web.Services @using GmRelay.Shared.Domain @using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Components.Authorization @attribute [Authorize] @inject AuthorizedSessionService SessionService @inject AuthenticationStateProvider AuthStateProvider @inject NavigationManager Navigation Редактирование сессии — GM-Relay
@if (session == null) {
} else {
Изменение этого поля обновит все сессии в одной группе.
Текущее: @session.ScheduledAt.FormatMoscow()
Пустое значение означает запись без лимита. Если лимит заполнен, новые игроки попадут в лист ожидания.
@if (!string.IsNullOrEmpty(errorMessage)) {
⚠️ @errorMessage
} }
@code { [Parameter] public Guid SessionId { get; set; } private WebSession? session; private SessionEditModel model = new(); private bool isSubmitting; private string? errorMessage; protected override async Task OnInitializedAsync() { var authState = await AuthStateProvider.GetAuthenticationStateAsync(); if (!authState.User.TryGetTelegramId(out var telegramId)) { Navigation.NavigateTo("/access-denied"); return; } session = await SessionService.GetSessionForGmAsync(SessionId, telegramId); if (session is null) { Navigation.NavigateTo("/access-denied"); return; } model.Title = session.Title; model.ScheduledAtLocal = session.ScheduledAt.ToMoscow(); model.JoinLink = session.JoinLink; model.MaxPlayers = session.MaxPlayers; } private async Task HandleSubmit() { isSubmitting = true; errorMessage = null; try { var authState = await AuthStateProvider.GetAuthenticationStateAsync(); if (!authState.User.TryGetTelegramId(out var telegramId)) { Navigation.NavigateTo("/access-denied"); return; } var utcTime = new DateTimeOffset(model.ScheduledAtLocal, TimeSpan.FromHours(3)).ToUniversalTime().UtcDateTime; await SessionService.UpdateSessionForGmAsync(SessionId, telegramId, model.Title, utcTime, model.JoinLink, model.MaxPlayers); Navigation.NavigateTo($"/group/{session!.GroupId}"); } catch (SessionAccessDeniedException) { Navigation.NavigateTo("/access-denied"); } catch (Exception ex) { errorMessage = "Не удалось сохранить изменения: " + ex.Message; } finally { isSubmitting = false; } } private void GoBack() => Navigation.NavigateTo("/"); public class SessionEditModel { public string Title { get; set; } = ""; public DateTime ScheduledAtLocal { get; set; } = DateTime.Now; public string JoinLink { get; set; } = ""; public int? MaxPlayers { get; set; } } }