| | 1 | | @using Syki.Front.Features.Academic.GetCourses |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Features.Academic.CreateDiscipline |
| | 4 | |
|
| | 5 | | <MudDialog Class="pb-2"> |
| | 6 | | <TitleContent> |
| | 7 | | <SykiDialogTitle Text="Nova Disciplina" /> |
| | 8 | | </TitleContent> |
| | 9 | | <DialogContent> |
| 0 | 10 | | <MudForm @ref="@_form" Class="pt-1"> |
| 0 | 11 | | <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@_name" /> |
| 0 | 12 | | <MudSelect |
| 0 | 13 | | Dense="true" |
| 0 | 14 | | Margin="Margin.Dense" |
| 0 | 15 | | Variant="Variant.Outlined" |
| | 16 | | Class="mb-2" |
| | 17 | | T="CourseOut" |
| | 18 | | Label="Cursos" |
| | 19 | | MultiSelection="true" |
| | 20 | | @bind-SelectedValues="@SelectedCourses" |
| | 21 | | AnchorOrigin="Origin.BottomCenter" |
| | 22 | | > |
| 0 | 23 | | @foreach (var course in _courses) |
| | 24 | | { |
| | 25 | | <MudSelectItem Class="d-flex align-start gap-0" T="CourseOut" Value="@course">@course.Name</MudSelec |
| | 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 GetCoursesClient GetCoursesClient |
| | 39 | | @inject CreateDisciplineClient CreateDisciplineClient |
| | 40 | |
|
| | 41 | | @code |
| | 42 | | { |
| | 43 | | [CascadingParameter] |
| 0 | 44 | | MudDialogInstance MudDialog { get; set; } |
| | 45 | |
|
| | 46 | | MudForm _form; |
| | 47 | | private bool _loading; |
| | 48 | | private string _name; |
| | 49 | |
|
| 0 | 50 | | private List<CourseOut> _courses = []; |
| 0 | 51 | | IEnumerable<CourseOut> SelectedCourses { get; set; } = new HashSet<CourseOut>(); |
| | 52 | |
|
| | 53 | | protected override async Task OnInitializedAsync() |
| | 54 | | { |
| 0 | 55 | | _courses = await GetCoursesClient.Get(); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | private async Task Submit() |
| | 59 | | { |
| 0 | 60 | | if (_loading) return; |
| | 61 | |
|
| 0 | 62 | | await _form.Validate(); |
| 0 | 63 | | if (!_form.IsValid) return; |
| | 64 | |
|
| 0 | 65 | | _loading = true; |
| 0 | 66 | | var response = await CreateDisciplineClient.Create(_name, SelectedCourses.ToList().ConvertAll(c => c.Id)); |
| 0 | 67 | | if (response.IsSuccessStatusCode) |
| | 68 | | { |
| 0 | 69 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 70 | | Snackbar.Add("Disciplina cadastrada com sucesso!", Severity.Success); |
| | 71 | | } |
| | 72 | | else |
| | 73 | | { |
| 0 | 74 | | var error = await response.ToError(); |
| 0 | 75 | | Snackbar.Add(error.Message, Severity.Error); |
| | 76 | | } |
| 0 | 77 | | _loading = false; |
| 0 | 78 | | } |
| | 79 | |
|
| 0 | 80 | | void Cancel() => MudDialog.Cancel(); |
| | 81 | | } |