< Summary

Information
Class: Syki.Front.Features.Academic.UpdateEnrollmentPeriod.UpdateEnrollmentPeriodDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/UpdateEnrollmentPeriod/UpdateEnrollmentPeriodDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 26
Coverable lines: 26
Total lines: 79
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
get_Period()100%210%
OnInitialized()100%210%
Submit()0%4260%
Cancel()100%210%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/UpdateEnrollmentPeriod/UpdateEnrollmentPeriodDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.UpdateEnrollmentPeriod
 2
 3<MudDialog Class="pb-2" Style="min-height: 450px">
 4    <TitleContent>
 5        <MudText Typo="Typo.h6">
 6            <MudIcon Icon="@Icons.Material.Outlined.Edit" Class="mr-1 mb-n1" />
 7            Editar Período de Matrícula
 8        </MudText>
 9    </TitleContent>
 10    <DialogContent>
 011        <MudForm @ref="@_form" Class="py-1">
 012            <MudGrid Spacing="2">
 013                <MudFlexBreak />
 014                <MudItem xs="12">
 015                    <SykiDatePicker Label="Início" @bind-Date="@_start"/>
 016                </MudItem>
 17                <MudItem xs="12">
 18                    <SykiDatePicker Label="Fim" @bind-Date="@_end"/>
 19                </MudItem>
 20            </MudGrid>
 21        </MudForm>
 22    </DialogContent>
 23    <DialogActions>
 24        <DialogCancelButton OnClick="@Cancel" />
 25        <SykiProgressCircular Loading="@_loading" />
 26        <DialogSaveButton OnClick="@Submit" />
 27    </DialogActions>
 28</MudDialog>
 29
 30@inject ISnackbar Snackbar
 31@inject UpdateEnrollmentPeriodClient Client
 32
 33@code
 34{
 35    [CascadingParameter]
 036    MudDialogInstance MudDialog { get; set; }
 37
 38    [Parameter]
 039    public EnrollmentPeriodOut Period { get; set; }
 40
 41    private MudForm _form;
 42    private bool _loading;
 43
 44    private DateTime? _start;
 45    private DateTime? _end;
 46
 47    protected override void OnInitialized()
 48    {
 049        base.OnInitialized();
 050        _start = Period.StartAt.ToDateTime();
 051        _end = Period.EndAt.ToDateTime();
 052    }
 53
 54    async Task Submit()
 55    {
 056        if (_loading) return;
 57
 058        await _form.Validate();
 059        if (!_form.IsValid) return;
 60
 061        var start = DateOnly.FromDateTime(_start!.Value);
 062        var end = DateOnly.FromDateTime(_end!.Value);
 63
 064        _loading = true;
 065        var response = await Client.Update(Period.Id, start, end);
 066        if (response.IsSuccess())
 67        {
 068            MudDialog.Close(DialogResult.Ok(true));
 069            Snackbar.Add("Período editado com sucesso!", Severity.Success);
 70        }
 71        else
 72        {
 073            Snackbar.Add(response.GetError().Message, Severity.Error);
 74        }
 075        _loading = false;
 076    }
 77
 078    void Cancel() => MudDialog.Cancel();
 79}