< Summary

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

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/CreateAcademicPeriod/CreateAcademicPeriodDialog.razor

#LineLine coverage
 1@using System.Globalization
 2@namespace Syki.Front.Features.Academic.CreateAcademicPeriod
 3
 4<MudDialog Class="pb-2" Style="min-height: 450px">
 5    <TitleContent>
 6        <SykiDialogTitle Text="Novo Período Acadêmico" />
 7    </TitleContent>
 8    <DialogContent>
 09        <MudForm @ref="@_form" Class="py-1">
 010            <MudGrid Spacing="2">
 011                <MudItem xs="12">
 012                    <MudNumericField
 013                        T="decimal"
 014                        @bind-Value="@_id"
 15                        Max="2050.1M"
 16                        MaxLength="6"
 17                        Min="1970.1M"
 18                        Format="####.#"
 19                        Culture="CultureInfo.InvariantCulture"
 20                        HideSpinButtons="true"
 21                        Variant="Variant.Outlined"
 22                        Margin="Margin.Dense"
 23                        HelperText="Exemplo: 2024.1"
 24                        Required="true"
 25                        Label="Id"
 26                        RequiredError="Informe!"
 27                    />
 28                </MudItem>
 29                <MudItem xs="12">
 30                    <SykiDatePicker Label="Início" @bind-Date="@_start" Editable="false" />
 31                </MudItem>
 32                <MudItem xs="12" Class="mb-4">
 33                    <SykiDatePicker Label="Fim" @bind-Date="@_end" Editable="false" />
 34                </MudItem>
 35            </MudGrid>
 36        </MudForm>
 37    </DialogContent>
 38    <DialogActions>
 39        <DialogCancelButton OnClick="@Cancel"/>
 40        <SykiProgressCircular Loading="@_loading"/>
 41        <DialogSaveButton OnClick="@Submit"/>
 42    </DialogActions>
 43</MudDialog>
 44
 45@inject ISnackbar Snackbar
 46@inject CreateAcademicPeriodClient Client
 47
 48@code
 49{
 50    [CascadingParameter]
 051    MudDialogInstance MudDialog { get; set; }
 52
 53    private MudForm _form;
 54    private bool _loading;
 55
 056    private decimal _id = DateTime.Now.Year + 0.1M;
 57    private DateTime? _start;
 58    private DateTime? _end;
 59
 60    private string GetIdHelperText()
 61    {
 062        return $"Exemplo: {DateTime.Now.Year + 0.1M}";
 63    }
 64
 65    private async Task Submit()
 66    {
 067        if (_loading) return;
 68
 069        await _form.Validate();
 070        if (!_form.IsValid) return;
 71
 072        var start = DateOnly.FromDateTime(_start!.Value);
 073        var end = DateOnly.FromDateTime(_end!.Value);
 74
 075        _loading = true;
 076        var response = await Client.Create(_id.ToString("####.#", CultureInfo.InvariantCulture), start, end);
 077        if (response.IsSuccess())
 78        {
 079            MudDialog.Close(DialogResult.Ok(true));
 080            Snackbar.Add("Período acadêmico cadastrado com sucesso!", Severity.Success);
 81        }
 82        else
 83        {
 084            Snackbar.Add(response.GetError().Message, Severity.Error);
 85        }
 086        _loading = false;
 087    }
 88
 089    private void Cancel() => MudDialog.Cancel();
 90}