< Summary

Information
Class: Syki.Front.Features.Academic.CreateStudent.CreateStudentDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/CreateStudent/CreateStudentDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 84
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%
OnInitializedAsync()100%210%
Submit()0%4260%
Cancel()100%210%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/CreateStudent/CreateStudentDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.CreateStudent
 2
 3<MudDialog Class="pb-2">
 4    <TitleContent>
 5        <SykiDialogTitle Text="Novo Aluno" />
 6    </TitleContent>
 7    <DialogContent>
 08        <MudForm @ref="@_form" Class="pt-1">
 09            <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@_name" />
 010            <SykiTextField Label="Email" @bind-Value="@_email" />
 011            <MudSelect
 012                Dense="true"
 013                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="true"
 20                RequiredError="Informe!"
 21                AdornmentColor="Color.Primary
 22            ">
 023                @foreach (CourseOfferingOut? item in _courseOfferings)
 24                {
 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]
 044    MudDialogInstance MudDialog { get; set; }
 45
 46    private MudForm _form;
 47    private bool _loading;
 48
 49    private CourseOfferingOut? _courseOffering;
 050    private List<CourseOfferingOut> _courseOfferings = [];
 51
 52    private string _name;
 53    private string _email;
 54
 55    protected override async Task OnInitializedAsync()
 56    {
 057        _courseOfferings = await GetCourseOfferingsClient.Get();
 058    }
 59
 60    async Task Submit()
 61    {
 062        if (_loading) return;
 63
 064        await _form.Validate();
 065        if (!_form.IsValid) return;
 66
 067        var courseOfferingId = _courseOffering!.Id;
 68
 069        _loading = true;
 070        var response = await CreateStudentClient.Create(_name, _email, courseOfferingId);
 071        if (response.IsSuccess())
 72        {
 073            MudDialog.Close(DialogResult.Ok(true));
 074            Snackbar.Add("Aluno cadastrado com sucesso!", Severity.Success);
 75        }
 76        else
 77        {
 078            Snackbar.Add(response.GetError().Message, Severity.Error);
 79        }
 080        _loading = false;
 081    }
 82
 083    void Cancel() => MudDialog.Cancel();
 84}