| | 1 | | @using System.Globalization |
| | 2 | | @namespace Syki.Front.Features.Academic.CreateAcademicPeriod |
| | 3 | |
|
| | 4 | | <MudDialog Class="pb-2" Style="min-height: 450px"> |
| | 5 | | <TitleContent> |
| | 6 | | <SykiDialogTitle Text="Novo Período Acadêmico" /> |
| | 7 | | </TitleContent> |
| | 8 | | <DialogContent> |
| 0 | 9 | | <MudForm @ref="@_form" Class="py-1"> |
| 0 | 10 | | <MudGrid Spacing="2"> |
| 0 | 11 | | <MudItem xs="12"> |
| 0 | 12 | | <MudNumericField |
| 0 | 13 | | T="decimal" |
| 0 | 14 | | @bind-Value="@_id" |
| | 15 | | Max="2050.1M" |
| | 16 | | MaxLength="6" |
| | 17 | | Min="1970.1M" |
| | 18 | | Format="####.#" |
| | 19 | | Culture="CultureInfo.InvariantCulture" |
| | 20 | | HideSpinButtons="true" |
| | 21 | | Variant="Variant.Outlined" |
| | 22 | | Margin="Margin.Dense" |
| | 23 | | HelperText="Exemplo: 2024.1" |
| | 24 | | Required="true" |
| | 25 | | Label="Id" |
| | 26 | | RequiredError="Informe!" |
| | 27 | | /> |
| | 28 | | </MudItem> |
| | 29 | | <MudItem xs="12"> |
| | 30 | | <SykiDatePicker Label="Início" @bind-Date="@_start" Editable="false" /> |
| | 31 | | </MudItem> |
| | 32 | | <MudItem xs="12" Class="mb-4"> |
| | 33 | | <SykiDatePicker Label="Fim" @bind-Date="@_end" Editable="false" /> |
| | 34 | | </MudItem> |
| | 35 | | </MudGrid> |
| | 36 | | </MudForm> |
| | 37 | | </DialogContent> |
| | 38 | | <DialogActions> |
| | 39 | | <DialogCancelButton OnClick="@Cancel"/> |
| | 40 | | <SykiProgressCircular Loading="@_loading"/> |
| | 41 | | <DialogSaveButton OnClick="@Submit"/> |
| | 42 | | </DialogActions> |
| | 43 | | </MudDialog> |
| | 44 | |
|
| | 45 | | @inject ISnackbar Snackbar |
| | 46 | | @inject CreateAcademicPeriodClient Client |
| | 47 | |
|
| | 48 | | @code |
| | 49 | | { |
| | 50 | | [CascadingParameter] |
| 0 | 51 | | MudDialogInstance MudDialog { get; set; } |
| | 52 | |
|
| | 53 | | private MudForm _form; |
| | 54 | | private bool _loading; |
| | 55 | |
|
| 0 | 56 | | private decimal _id = DateTime.Now.Year + 0.1M; |
| | 57 | | private DateTime? _start; |
| | 58 | | private DateTime? _end; |
| | 59 | |
|
| | 60 | | private string GetIdHelperText() |
| | 61 | | { |
| 0 | 62 | | return $"Exemplo: {DateTime.Now.Year + 0.1M}"; |
| | 63 | | } |
| | 64 | |
|
| | 65 | | private async Task Submit() |
| | 66 | | { |
| 0 | 67 | | if (_loading) return; |
| | 68 | |
|
| 0 | 69 | | await _form.Validate(); |
| 0 | 70 | | if (!_form.IsValid) return; |
| | 71 | |
|
| 0 | 72 | | var start = DateOnly.FromDateTime(_start!.Value); |
| 0 | 73 | | var end = DateOnly.FromDateTime(_end!.Value); |
| | 74 | |
|
| 0 | 75 | | _loading = true; |
| 0 | 76 | | var response = await Client.Create(_id.ToString("####.#", CultureInfo.InvariantCulture), start, end); |
| 0 | 77 | | if (response.IsSuccess()) |
| | 78 | | { |
| 0 | 79 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 80 | | Snackbar.Add("Período acadêmico cadastrado com sucesso!", Severity.Success); |
| | 81 | | } |
| | 82 | | else |
| | 83 | | { |
| 0 | 84 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 85 | | } |
| 0 | 86 | | _loading = false; |
| 0 | 87 | | } |
| | 88 | |
|
| 0 | 89 | | private void Cancel() => MudDialog.Cancel(); |
| | 90 | | } |