175 lines
6.8 KiB
Plaintext
175 lines
6.8 KiB
Plaintext
@using Koogle.Application.DTOs
|
|
@using Koogle.Domain.Enums
|
|
|
|
<MudDialog>
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">
|
|
@if (IsInverseMode)
|
|
{
|
|
<text>Inverse Strafe hinzufügen</text>
|
|
}
|
|
else
|
|
{
|
|
<text>Strafe hinzufügen</text>
|
|
}
|
|
</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<MudForm @ref="_form" @bind-IsValid="_isValid">
|
|
<!-- Expense Selection -->
|
|
<MudSelect T="ExpenseDto"
|
|
Label="Strafe"
|
|
@bind-Value="_selectedExpense"
|
|
Required="true"
|
|
RequiredError="Bitte wählen Sie eine Strafe"
|
|
ToStringFunc="@(e => e?.Name ?? string.Empty)"
|
|
Class="mb-4">
|
|
@foreach (var expense in AvailableExpenses.OrderBy(e => e.Name))
|
|
{
|
|
<MudSelectItem T="ExpenseDto" Value="expense">
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Style="width: 100%">
|
|
<MudText>@expense.Name</MudText>
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
|
|
@if (expense.IsInverse)
|
|
{
|
|
<MudIcon Icon="@Icons.Material.Filled.SwapHoriz" Size="Size.Small" Color="Color.Warning" Title="Inverse" />
|
|
}
|
|
@if (expense.IsVariable)
|
|
{
|
|
<MudIcon Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Info" Title="Variable" />
|
|
}
|
|
<MudText Color="Color.Secondary">@expense.Price.ToString("C")</MudText>
|
|
</MudStack>
|
|
</MudStack>
|
|
</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
|
|
@if (_selectedExpense?.IsInverse == true)
|
|
{
|
|
<MudAlert Severity="Severity.Info" Class="mb-4">
|
|
<MudText Typo="Typo.body2">
|
|
<strong>Inverse Strafe:</strong> Die Strafe wird allen Teilnehmern <em>außer</em> der ausgewählten Person zugewiesen.
|
|
</MudText>
|
|
</MudAlert>
|
|
}
|
|
|
|
<!-- Person Selection -->
|
|
<MudSelect T="DayParticipantDto"
|
|
Label="@(_selectedExpense?.IsInverse == true ? "Person ausschließen" : "Person")"
|
|
@bind-Value="_selectedParticipant"
|
|
Required="true"
|
|
RequiredError="Bitte wählen Sie eine Person"
|
|
ToStringFunc="@(p => p?.PersonName ?? string.Empty)"
|
|
Class="mb-4">
|
|
@foreach (var participant in Participants.OrderBy(p => p.PersonName))
|
|
{
|
|
<MudSelectItem T="DayParticipantDto" Value="participant">
|
|
<MudStack Row="true" AlignItems="AlignItems.Center">
|
|
<MudAvatar Size="Size.Small" Color="@(participant.PersonStatus == PersonStatus.Member ? Color.Primary : Color.Secondary)">
|
|
@participant.PersonName[0]
|
|
</MudAvatar>
|
|
<MudText>@participant.PersonName</MudText>
|
|
@if (participant.PersonStatus == PersonStatus.Guest)
|
|
{
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Secondary">Gast</MudChip>
|
|
}
|
|
</MudStack>
|
|
</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
|
|
<!-- Variable Price -->
|
|
@if (_selectedExpense?.IsVariable == true)
|
|
{
|
|
<MudNumericField T="decimal"
|
|
Label="Preis"
|
|
@bind-Value="_customPrice"
|
|
Min="0"
|
|
Format="C"
|
|
Adornment="Adornment.Start"
|
|
AdornmentIcon="@Icons.Material.Filled.Euro"
|
|
Required="true"
|
|
RequiredError="Bitte geben Sie einen Preis ein" />
|
|
}
|
|
else if (_selectedExpense is not null)
|
|
{
|
|
<MudText Class="mb-4">
|
|
<strong>Preis:</strong> @_selectedExpense.Price.ToString("C")
|
|
</MudText>
|
|
}
|
|
</MudForm>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="Cancel">Abbrechen</MudButton>
|
|
<MudButton Color="Color.Primary"
|
|
Variant="Variant.Filled"
|
|
Disabled="@(!_isValid || _selectedExpense is null || _selectedParticipant is null)"
|
|
OnClick="Submit">
|
|
Hinzufügen
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter]
|
|
private IMudDialogInstance? MudDialog { get; set; }
|
|
|
|
[Parameter]
|
|
public IReadOnlyList<ExpenseDto> AvailableExpenses { get; set; } = [];
|
|
|
|
[Parameter]
|
|
public IReadOnlyList<DayParticipantDto> Participants { get; set; } = [];
|
|
|
|
[Parameter]
|
|
public Guid DayId { get; set; }
|
|
|
|
private MudForm? _form;
|
|
private bool _isValid;
|
|
private ExpenseDto? _selectedExpense;
|
|
private DayParticipantDto? _selectedParticipant;
|
|
private decimal _customPrice;
|
|
|
|
private bool IsInverseMode => _selectedExpense?.IsInverse == true;
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
base.OnParametersSet();
|
|
if (_selectedExpense is not null)
|
|
{
|
|
_customPrice = _selectedExpense.Price;
|
|
}
|
|
}
|
|
|
|
private void Cancel() => MudDialog?.Cancel();
|
|
|
|
private void Submit()
|
|
{
|
|
if (_selectedExpense is null || _selectedParticipant is null) return;
|
|
|
|
if (_selectedExpense.IsInverse)
|
|
{
|
|
var dto = new CreateInversePersonExpenseDto
|
|
{
|
|
ExcludedPersonId = _selectedParticipant.PersonId,
|
|
ExpenseId = _selectedExpense.Id,
|
|
DayId = DayId,
|
|
GameId = null
|
|
};
|
|
MudDialog?.Close(DialogResult.Ok(dto));
|
|
}
|
|
else
|
|
{
|
|
var dto = new CreatePersonExpenseDto
|
|
{
|
|
PersonId = _selectedParticipant.PersonId,
|
|
ExpenseId = _selectedExpense.Id,
|
|
DayId = DayId,
|
|
GameId = null,
|
|
Price = _selectedExpense.IsVariable ? _customPrice : null
|
|
};
|
|
MudDialog?.Close(DialogResult.Ok(dto));
|
|
}
|
|
}
|
|
}
|