< Summary

Information
Class: Syki.Front.Features.Academic.CreateDiscipline.CreateDisciplineDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/CreateDiscipline/CreateDisciplineDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 25
Coverable lines: 25
Total lines: 81
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_MudDialog()100%210%
.ctor()100%210%
get_SelectedCourses()100%210%
OnInitializedAsync()100%210%
Submit()0%4260%
Cancel()100%210%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/CreateDiscipline/CreateDisciplineDialog.razor

#LineLine coverage
 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>
 010        <MudForm @ref="@_form" Class="pt-1">
 011            <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@_name" />
 012            <MudSelect
 013                Dense="true"
 014                Margin="Margin.Dense"
 015                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            >
 023                @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]
 044    MudDialogInstance MudDialog { get; set; }
 45
 46    MudForm _form;
 47    private bool _loading;
 48    private string _name;
 49
 050    private List<CourseOut> _courses = [];
 051    IEnumerable<CourseOut> SelectedCourses { get; set; } = new HashSet<CourseOut>();
 52
 53    protected override async Task OnInitializedAsync()
 54    {
 055        _courses = await GetCoursesClient.Get();
 056    }
 57
 58    private async Task Submit()
 59    {
 060        if (_loading) return;
 61
 062        await _form.Validate();
 063        if (!_form.IsValid) return;
 64
 065        _loading = true;
 066        var response = await CreateDisciplineClient.Create(_name, SelectedCourses.ToList().ConvertAll(c => c.Id));
 067        if (response.IsSuccessStatusCode)
 68        {
 069            MudDialog.Close(DialogResult.Ok(true));
 070            Snackbar.Add("Disciplina cadastrada com sucesso!", Severity.Success);
 71        }
 72        else
 73        {
 074            var error = await response.ToError();
 075            Snackbar.Add(error.Message, Severity.Error);
 76        }
 077        _loading = false;
 078    }
 79
 080    void Cancel() => MudDialog.Cancel();
 81}