@page "/calendars/{calendarId:int}/events/{eventUid}"
@using System.Globalization
@inject Data.CalendarService _calendarService
@inject NavigationManager _navigationManager
Back
@if (_event == null)
{
@(_notFound ? "Event not found" : "Loading...")
}
else
{
Event
Summary:
@if (_editing != Editing.Summary)
{
_editing = Editing.Summary">
@_event.Summary
}
else
{
}
Start:
@if (_editing != Editing.DtStart)
{
_editing = Editing.DtStart">
@(_event.DtStart?.ToString(DtFormat) ?? "Unknown")
}
else
{
}
End:
@if (_editing != Editing.CalculatedEnd)
{
_editing = Editing.CalculatedEnd">
@(_event.CalculatedEnd?.ToString(DtFormat) ?? "Unknown")
}
else
{
}
@if (_editing != Editing.Description)
{
_editing = Editing.Description">
@(_event.Description ?? "No description")
}
else
{
}
@if (!_confirmDelete)
{
}
else
{
}
}
@code
{
[Parameter]
public int CalendarId { get; set; }
[Parameter]
public string EventUid { get; set; }
const string DtFormat = "dd-MM-yyyy HH:mm:ss";
private Data.Calendar _calendar;
private Data.Event _event;
private bool _notFound;
private bool _confirmDelete;
private enum Editing
{
Summary,
DtStart,
CalculatedEnd,
Description,
}
private Editing? _editing;
protected override async Task OnInitializedAsync()
{
_calendar = await Data.CalendarService.GetCalendarById(CalendarId);
_event = await _calendar.GetEventByUid(EventUid);
_notFound = _event == null;
}
private async Task UpdateEvent()
{
_event = await _calendar.UpdateEvent(_event);
_editing = null;
}
private async Task DeleteEvent()
{
if (!_confirmDelete)
{
_confirmDelete = true;
await Task.Delay(2000);
}
else
{
await _calendar.DeleteEvent(_event);
_navigationManager.NavigateTo($"/calendars/{CalendarId}");
}
_confirmDelete = false;
}
}