| | | 1 | | @namespace Syki.Front.Features.Academic.CreateStudent |
| | | 2 | | |
| | | 3 | | <MudDialog Class="pb-2" DefaultFocus="DefaultFocus.None"> |
| | | 4 | | <TitleContent> |
| | | 5 | | <SykiDialogTitle Text="Novo Aluno" /> |
| | | 6 | | </TitleContent> |
| | | 7 | | <DialogContent> |
| | 0 | 8 | | <MudForm @ref="@_form" Class="pt-1"> |
| | 0 | 9 | | <SykiTextField Label="Nome" AutoFocus @bind-Value="@_name" /> |
| | 0 | 10 | | <SykiTextField Label="Email" @bind-Value="@_email" /> |
| | 0 | 11 | | <MudSelect |
| | 0 | 12 | | Dense |
| | 0 | 13 | | Disabled="@(_courseOfferings.Count == 0)" |
| | | 14 | | Margin="Margin.Dense" |
| | | 15 | | Variant="Variant.Outlined" |
| | | 16 | | Class="mb-2" |
| | | 17 | | @bind-Value="@_courseOffering" |
| | | 18 | | Label="Oferta" |
| | | 19 | | Required |
| | | 20 | | RequiredError="Informe!" |
| | | 21 | | AdornmentColor="Color.Primary |
| | | 22 | | "> |
| | 0 | 23 | | @foreach (CourseOfferingOut? item in _courseOfferings) |
| | | 24 | | { |
| | 0 | 25 | | <MudSelectItem Value="@item">@item.ToString()</MudSelectItem> |
| | | 26 | | } |
| | | 27 | | </MudSelect> |
| | | 28 | | </MudForm> |
| | | 29 | | </DialogContent> |
| | | 30 | | <DialogActions> |
| | | 31 | | <DialogCancelButton OnClick="@Cancel" /> |
| | | 32 | | <SykiProgressCircular Loading="@_loading" /> |
| | | 33 | | <DialogSaveButton OnClick="@Submit" /> |
| | | 34 | | </DialogActions> |
| | | 35 | | </MudDialog> |
| | | 36 | | |
| | | 37 | | @inject ISnackbar Snackbar |
| | | 38 | | @inject CreateStudentClient CreateStudentClient |
| | | 39 | | @inject GetCourseOfferingsClient GetCourseOfferingsClient |
| | | 40 | | |
| | | 41 | | @code |
| | | 42 | | { |
| | | 43 | | [CascadingParameter] |
| | 0 | 44 | | IMudDialogInstance MudDialog { get; set; } |
| | | 45 | | |
| | | 46 | | private MudForm _form; |
| | | 47 | | private bool _loading; |
| | | 48 | | |
| | | 49 | | private CourseOfferingOut? _courseOffering; |
| | 0 | 50 | | private List<CourseOfferingOut> _courseOfferings = []; |
| | | 51 | | |
| | | 52 | | private string _name; |
| | | 53 | | private string _email; |
| | | 54 | | |
| | | 55 | | protected override async Task OnInitializedAsync() |
| | | 56 | | { |
| | 0 | 57 | | _courseOfferings = await GetCourseOfferingsClient.Get(); |
| | 0 | 58 | | } |
| | | 59 | | |
| | | 60 | | async Task Submit() |
| | | 61 | | { |
| | 0 | 62 | | if (_loading) return; |
| | | 63 | | |
| | 0 | 64 | | await _form.Validate(); |
| | 0 | 65 | | if (!_form.IsValid) return; |
| | | 66 | | |
| | 0 | 67 | | var courseOfferingId = _courseOffering!.Id; |
| | | 68 | | |
| | 0 | 69 | | _loading = true; |
| | 0 | 70 | | var response = await CreateStudentClient.Create(_name, _email, courseOfferingId); |
| | 0 | 71 | | if (response.IsSuccess) |
| | | 72 | | { |
| | 0 | 73 | | MudDialog.Close(DialogResult.Ok(true)); |
| | 0 | 74 | | Snackbar.Add("Aluno cadastrado com sucesso!", Severity.Success); |
| | | 75 | | } |
| | | 76 | | else |
| | | 77 | | { |
| | 0 | 78 | | Snackbar.Add(response.Error.Message, Severity.Error); |
| | | 79 | | } |
| | 0 | 80 | | _loading = false; |
| | 0 | 81 | | } |
| | | 82 | | |
| | 0 | 83 | | void Cancel() => MudDialog.Cancel(); |
| | | 84 | | } |