| | 1 | | @namespace Syki.Front.Features.Academic.CreateCourse |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2"> |
| | 4 | | <TitleContent> |
| | 5 | | <SykiDialogTitle Text="Novo Curso" /> |
| | 6 | | </TitleContent> |
| | 7 | | <DialogContent> |
| 0 | 8 | | <MudForm @ref="@_form" Class="pt-1"> |
| 0 | 9 | | <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@_name" /> |
| 0 | 10 | | <MudSelect |
| 0 | 11 | | Dense="true" |
| 0 | 12 | | Margin="Margin.Dense" |
| 0 | 13 | | Variant="Variant.Outlined" |
| | 14 | | Class="mb-2" |
| | 15 | | @bind-Value="@_type" |
| | 16 | | Label="Tipo" |
| | 17 | | Required="true" |
| | 18 | | RequiredError="Informe!" |
| | 19 | | AdornmentColor="Color.Primary |
| | 20 | | "> |
| 0 | 21 | | @foreach (CourseType? item in Enum.GetValues<CourseType>()) |
| | 22 | | { |
| | 23 | | <MudSelectItem Value="@item">@item.GetDescription()</MudSelectItem> |
| | 24 | | } |
| | 25 | | </MudSelect> |
| | 26 | | </MudForm> |
| | 27 | | </DialogContent> |
| | 28 | | <DialogActions> |
| | 29 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 30 | | <SykiProgressCircular Loading="@_loading" /> |
| | 31 | | <DialogSaveButton OnClick="@Submit" /> |
| | 32 | | </DialogActions> |
| | 33 | | </MudDialog> |
| | 34 | |
|
| | 35 | | @inject ISnackbar Snackbar |
| | 36 | | @inject CreateCourseClient Client |
| | 37 | |
|
| | 38 | | @code |
| | 39 | | { |
| | 40 | | [CascadingParameter] |
| 0 | 41 | | MudDialogInstance MudDialog { get; set; } |
| | 42 | |
|
| | 43 | | private MudForm _form; |
| | 44 | | private bool _loading; |
| | 45 | | private string _name; |
| | 46 | | private CourseType? _type; |
| | 47 | |
|
| | 48 | | async Task Submit() |
| | 49 | | { |
| 0 | 50 | | if (_loading) return; |
| | 51 | |
|
| 0 | 52 | | await _form.Validate(); |
| 0 | 53 | | if (!_form.IsValid) return; |
| | 54 | |
|
| 0 | 55 | | _loading = true; |
| 0 | 56 | | var response = await Client.Create(_name, _type!.Value); |
| 0 | 57 | | if (response.IsSuccess()) |
| | 58 | | { |
| 0 | 59 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 60 | | Snackbar.Add("Curso cadastrado com sucesso!", Severity.Success); |
| | 61 | | } |
| | 62 | | else |
| | 63 | | { |
| 0 | 64 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 65 | | } |
| 0 | 66 | | _loading = false; |
| 0 | 67 | | } |
| | 68 | |
|
| 0 | 69 | | void Cancel() => MudDialog.Cancel(); |
| | 70 | | } |