| | 1 | | @namespace Syki.Front.Features.Academic.CreateClassroom |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2" DefaultFocus="DefaultFocus.None"> |
| | 4 | | <TitleContent> |
| | 5 | | <MudText Typo="Typo.h6"> |
| | 6 | | <MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1 mb-n1" /> |
| | 7 | | Nova Sala |
| | 8 | | </MudText> |
| | 9 | | </TitleContent> |
| | 10 | | <DialogContent> |
| 0 | 11 | | <MudForm @ref="@_form" Class="pt-1"> |
| 0 | 12 | | <MudSelect |
| 0 | 13 | | Dense="true" |
| 0 | 14 | | Margin="Margin.Dense" |
| 0 | 15 | | Variant="Variant.Outlined" |
| 0 | 16 | | Class="pb-2" |
| | 17 | | AutoFocus="true" |
| | 18 | | @bind-Value="@_campus" |
| | 19 | | Label="Campus" |
| | 20 | | Required="true" |
| | 21 | | RequiredError="Informe!" |
| | 22 | | AdornmentColor="Color.Primary" |
| | 23 | | > |
| 0 | 24 | | @foreach (CampusOut? item in _campi) |
| | 25 | | { |
| 0 | 26 | | <MudSelectItem Value="@item">@item.Name</MudSelectItem> |
| | 27 | | } |
| | 28 | | </MudSelect> |
| | 29 | |
|
| | 30 | | <MudTextField |
| | 31 | | OnlyValidateIfDirty="true" |
| | 32 | | Immediate="true" |
| | 33 | | Margin="Margin.Dense" |
| | 34 | | Variant="Variant.Outlined" |
| | 35 | | Class="pb-2" |
| | 36 | | AutoFocus="true" |
| | 37 | | @bind-Value="@_name" |
| | 38 | | T="String" |
| | 39 | | Label="Nome" |
| | 40 | | Required="true" |
| | 41 | | RequiredError="Informe!" |
| | 42 | | /> |
| | 43 | |
|
| | 44 | | <MudNumericField |
| | 45 | | MaxLength="5" |
| | 46 | | HideSpinButtons="true" |
| | 47 | | Margin="Margin.Dense" |
| | 48 | | Variant="Variant.Outlined" |
| | 49 | | @bind-Value="@_capacity" |
| | 50 | | Label="Capacidade" |
| | 51 | | Required="true" |
| | 52 | | RequiredError="Informe!" |
| | 53 | | /> |
| | 54 | | </MudForm> |
| | 55 | | </DialogContent> |
| | 56 | | <DialogActions> |
| | 57 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 58 | | <SykiProgressCircular Loading="@_loading" /> |
| | 59 | | <DialogSaveButton OnClick="@Submit" /> |
| | 60 | | </DialogActions> |
| | 61 | | </MudDialog> |
| | 62 | |
|
| | 63 | | @inject ISnackbar Snackbar |
| | 64 | | @inject CreateClassroomClient Client |
| | 65 | | @inject GetCampiClient GetCampiClient |
| | 66 | |
|
| | 67 | | @code |
| | 68 | | { |
| | 69 | | [CascadingParameter] |
| 0 | 70 | | IMudDialogInstance MudDialog { get; set; } |
| | 71 | |
|
| | 72 | | private MudForm _form; |
| | 73 | | private bool _loading; |
| | 74 | |
|
| | 75 | | private CampusOut? _campus; |
| 0 | 76 | | private List<CampusOut> _campi = []; |
| | 77 | | private string _name; |
| 0 | 78 | | private int _capacity = 25; |
| | 79 | |
|
| | 80 | | protected override async Task OnInitializedAsync() |
| | 81 | | { |
| 0 | 82 | | _campi = await GetCampiClient.Get(); |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | async Task Submit() |
| | 86 | | { |
| 0 | 87 | | if (_loading) return; |
| | 88 | |
|
| 0 | 89 | | await _form.Validate(); |
| 0 | 90 | | if (!_form.IsValid) return; |
| | 91 | |
|
| 0 | 92 | | _loading = true; |
| 0 | 93 | | var response = await Client.Create(_campus.Id, _name, _capacity); |
| 0 | 94 | | if (response.IsSuccess) |
| | 95 | | { |
| 0 | 96 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 97 | | Snackbar.Add("Sala cadastrada com sucesso!", Severity.Success); |
| | 98 | | } |
| | 99 | | else |
| | 100 | | { |
| 0 | 101 | | Snackbar.Add(response.Error.Message, Severity.Error); |
| | 102 | | } |
| 0 | 103 | | _loading = false; |
| 0 | 104 | | } |
| | 105 | |
|
| 0 | 106 | | void Cancel() => MudDialog.Cancel(); |
| | 107 | | } |