Skip to content

Commit e776c86

Browse files
committed
clean code
1 parent 4197f48 commit e776c86

4 files changed

Lines changed: 39 additions & 43 deletions

File tree

src/Templates/Pages/.create.razor.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
@code {
3333
public string? Title { get; private set; }
34-
MudForm? _{itemnamelowercase}Form;
34+
MudForm _{itemnamelowercase}Form = new();
3535
private bool _saving = false;
3636
private List<BreadcrumbItem>? _breadcrumbItems;
3737
private Create{itemname}Command _model = new();
@@ -51,8 +51,8 @@
5151
try
5252
{
5353
_saving = true;
54-
await _{itemnamelowercase}Form!.Validate().ConfigureAwait(false);
55-
if (!_{itemnamelowercase}Form!.IsValid)
54+
await _{itemnamelowercase}Form.Validate().ConfigureAwait(false);
55+
if (!_{itemnamelowercase}Form.IsValid)
5656
return;
5757
var result = await Mediator.Send(_model);
5858
result.Match(

src/Templates/Pages/.edit.razor.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
public string? Title { get; private set; }
4040
[Parameter]
4141
public int Id { get; set; }
42-
MudForm? _{itemnamelowercase}Form;
42+
MudForm _{itemnamelowercase}Form = new();
4343
private bool _saving = false;
4444
private List<BreadcrumbItem>? _breadcrumbItems;
4545
private Update{itemname}Command? _model;
@@ -70,8 +70,8 @@
7070
try
7171
{
7272
_saving = true;
73-
await _{itemnamelowercase}Form!.Validate().ConfigureAwait(false);
74-
if (!_{itemnamelowercase}Form!.IsValid)
73+
await _{itemnamelowercase}Form.Validate().ConfigureAwait(false);
74+
if (!_{itemnamelowercase}Form.IsValid)
7575
return;
7676
var result = await Mediator.Send(_model);
7777
result.Match(

src/Templates/Pages/.razor.txt

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -211,73 +211,69 @@
211211
}
212212
private async Task ShowEditFormDialog(string title, AddEdit{itemname}Command command)
213213
{
214-
var parameters = new DialogParameters<{itemname}FormDialog>
214+
return DialogServiceHelper.ShowFormDialogAsync<{itemname}FormDialog, AddEdit{itemname}Command>(
215+
title,
216+
command,
217+
async () =>
215218
{
216-
{ x=>x._model,command },
217-
};
218-
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
219-
var dialog = await DialogService.ShowAsync<{itemname}FormDialog>(title, parameters, options);
220-
var state = await dialog.Result;
221-
222-
if (state != null && !state.Canceled)
223-
{
224-
await _{nameofplurallowercase}Grid.ReloadServerData();
225-
_selected{nameofPlural}.Clear();
226-
}
219+
await _{nameofplurallowercase}Grid.ReloadServerData();
220+
_selected{nameofPlural}.Clear();
221+
});
227222
}
228223
private void OnDataGridRowClick({itemname}Dto dto)
229224
{
230225
Navigation.NavigateTo($"/pages/{nameofplurallowercase}/view/{dto.Id}");
231226
}
232-
private async Task OnCreate()
227+
private Task OnCreate()
233228
{
234229
var command = new AddEdit{itemname}Command();
235-
await ShowEditFormDialog(L["New {itemname}"], command);
230+
return ShowEditFormDialog(L["New {itemname}"], command);
236231
}
237-
private async Task OnClone{itemname}()
232+
private Task OnClone{itemname}()
238233
{
239234
var dto = _selected{nameofPlural}.First();
240235
var command = new AddEdit{itemname}Command()
241236
{
242237
{fieldAssignmentDefinition}
243238
};
244-
await ShowEditFormDialog(L["Clone {itemname}"], command);
239+
return ShowEditFormDialog(L["Clone {itemname}"], command);
245240
}
246-
private async Task OnEdit{itemname}({itemname}Dto dto)
241+
private Task OnEdit{itemname}({itemname}Dto dto)
247242
{
248243
//var command = Mapper.Map<AddEdit{itemname}Command>(dto);
249-
//await ShowEditFormDialog(L["Edit {itemname}"], command);
244+
//return ShowEditFormDialog(L["Edit {itemname}"], command);
250245
Navigation.NavigateTo($"/pages/{nameofplurallowercase}/edit/{dto.Id}");
246+
return Task.CompletedTask;
251247
}
252248

253-
private async Task OnDelete{itemname}({itemname}Dto dto)
249+
private Task OnDelete{itemname}({itemname}Dto dto)
254250
{
255251
var contentText = string.Format(ConstantString.DeleteConfirmation, dto.Name);
256252
var command = new Delete{itemname}Command(new int[] { dto.Id });
257-
await DialogServiceHelper.ShowDeleteConfirmationDialogAsync(command, ConstantString.DeleteConfirmationTitle, contentText,async () =>
258-
{
259-
await InvokeAsync(async () =>
260-
{
261-
await _{nameofplurallowercase}Grid.ReloadServerData();
262-
_selected{nameofPlural}.Clear();
263-
});
264-
});
253+
return Delete{nameofPlural}Internal(command, contentText);
265254
}
266255

267-
private async Task OnDeleteSelected{nameofPlural}()
256+
private Task OnDeleteSelected{nameofPlural}()
268257
{
269258
var contentText = string.Format(ConstantString.DeleteConfirmWithSelected, _selected{nameofPlural}.Count);
270259
var command = new Delete{itemname}Command(_selected{nameofPlural}.Select(x => x.Id).ToArray());
271-
await DialogServiceHelper.ShowDeleteConfirmationDialogAsync(command, ConstantString.DeleteConfirmationTitle, contentText,async () =>
272-
{
273-
await InvokeAsync(async () =>
260+
return Delete{nameofPlural}Internal(command, contentText);
261+
}
262+
263+
private Task Delete{nameofPlural}Internal(Delete{itemname}Command command, string contentText)
264+
{
265+
return DialogServiceHelper.ShowDeleteConfirmationDialogAsync(
266+
command,
267+
ConstantString.DeleteConfirmationTitle,
268+
contentText,
269+
async () =>
274270
{
275271
await _{nameofplurallowercase}Grid.ReloadServerData();
276272
_selected{nameofPlural}.Clear();
277273
});
278-
});
279274
}
280275

276+
281277
private async Task OnExport()
282278
{
283279
_exporting = true;

src/Templates/Pages/Components/.formdialog.razor.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</MudDialog>
2222

2323
@code {
24-
MudForm? _{itemnamelowercase}Form;
24+
MudForm _{itemnamelowercase}Form = new();
2525
private bool _saving = false;
2626
private bool _savingnew = false;
2727
[CascadingParameter]
@@ -32,8 +32,8 @@
3232
try
3333
{
3434
_saving = true;
35-
await _{itemnamelowercase}Form!.Validate().ConfigureAwait(false);
36-
if (!_{itemnamelowercase}Form!.IsValid)
35+
await _{itemnamelowercase}Form.Validate().ConfigureAwait(false);
36+
if (!_{itemnamelowercase}Form.IsValid)
3737
return;
3838
var result = await Mediator.Send(_model);
3939
result.Match(data =>
@@ -55,8 +55,8 @@
5555
try
5656
{
5757
_savingnew = true;
58-
await _{itemnamelowercase}Form!.Validate().ConfigureAwait(false);
59-
if (!_{itemnamelowercase}Form!.IsValid)
58+
await _{itemnamelowercase}Form.Validate().ConfigureAwait(false);
59+
if (!_{itemnamelowercase}Form.IsValid)
6060
return;
6161
var result = await Mediator.Send(_model);
6262
await result.MatchAsync(async data =>

0 commit comments

Comments
 (0)