< Summary

Information
Class: Syki.Front.Features.Academic.CreateEnrollmentPeriod.CreateEnrollmentPeriodDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/CreateEnrollmentPeriod/CreateEnrollmentPeriodDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 25
Coverable lines: 25
Total lines: 96
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/CreateEnrollmentPeriod/CreateEnrollmentPeriodDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.CreateEnrollmentPeriod
 2
 3<MudDialog Class="pb-2" Style="min-height: 450px">
 4    <TitleContent>
 5        <MudText Typo="Typo.h6">
 6            <MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1 mb-n1" />
 7            Novo Período de Matrícula
 8        </MudText>
 9    </TitleContent>
 10    <DialogContent>
 011        <MudForm @ref="@_form" Class="py-1">
 012            <MudGrid Spacing="2">
 013                <MudItem xs="12">
 014                    <MudSelect
 015                        Dense="true"
 016                        AutoFocus="true"
 17                        Margin="Margin.Dense"
 18                        Variant="Variant.Outlined"
 19                        Class="mb-4"
 20                        @bind-Value="@_id"
 21                        Label="Período Acadêmico"
 22                        Required="true"
 23                        RequiredError="Informe!"
 24                        AdornmentColor="Color.Primary"
 25                    >
 026                        @foreach (string? item in _periods.ConvertAll(p => p.Id))
 27                        {
 28                            <MudSelectItem Value="@item">@item</MudSelectItem>
 29                        }
 30                    </MudSelect>
 31                </MudItem>
 32                <MudItem xs="12">
 33                    <SykiDatePicker Label="Início" @bind-Date="@_start" Editable="false" />
 34                </MudItem>
 35                <MudItem xs="12">
 36                    <SykiDatePicker Label="Fim" @bind-Date="@_end" Editable="false" />
 37                </MudItem>
 38            </MudGrid>
 39        </MudForm>
 40    </DialogContent>
 41    <DialogActions>
 42        <DialogCancelButton OnClick="@Cancel" />
 43        <SykiProgressCircular Loading="@_loading" />
 44        <DialogSaveButton OnClick="@Submit" />
 45    </DialogActions>
 46</MudDialog>
 47
 48@inject ISnackbar Snackbar
 49@inject GetAcademicPeriodsClient GetClient
 50@inject CreateEnrollmentPeriodClient CreateClient
 51
 52@code
 53{
 54    [CascadingParameter]
 055    MudDialogInstance MudDialog { get; set; }
 56
 57    private MudForm _form;
 58    private bool _loading;
 59
 60    private string _id;
 61    private DateTime? _start;
 62    private DateTime? _end;
 63
 064    List<AcademicPeriodOut> _periods = [];
 65
 66    protected override async Task OnInitializedAsync()
 67    {
 068        _periods = await GetClient.Get();
 069    }
 70
 71    async Task Submit()
 72    {
 073        if (_loading) return;
 74
 075        await _form.Validate();
 076        if (!_form.IsValid) return;
 77
 078        var start = DateOnly.FromDateTime(_start!.Value);
 079        var end = DateOnly.FromDateTime(_end!.Value);
 80
 081        _loading = true;
 082        var response = await CreateClient.Create(_id, start, end);
 083        if (response.IsSuccess())
 84        {
 085            MudDialog.Close(DialogResult.Ok(true));
 086            Snackbar.Add("Período cadastrado com sucesso!", Severity.Success);
 87        }
 88        else
 89        {
 090            Snackbar.Add(response.GetError().Message, Severity.Error);
 91        }
 092        _loading = false;
 093    }
 94
 095    void Cancel() => MudDialog.Cancel();
 96}