From 3b5115392603cdeee91d70e7b288cd2d3e380f67 Mon Sep 17 00:00:00 2001 From: Ahmet Date: Thu, 4 Feb 2021 16:17:30 +0300 Subject: [PATCH] Added validations to author create & edit modals --- docs/en/Tutorials/Part-9.md | 176 +++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 62 deletions(-) diff --git a/docs/en/Tutorials/Part-9.md b/docs/en/Tutorials/Part-9.md index a1b4b03e21..d416052260 100644 --- a/docs/en/Tutorials/Part-9.md +++ b/docs/en/Tutorials/Part-9.md @@ -843,8 +843,10 @@ Create a new Razor Component Page, `/Pages/Authors.razor`, in the `Acme.BookStor ````xml @page "/authors" @using Acme.BookStore.Authors +@using Acme.BookStore.Localization @inherits BookStoreComponentBase @inject IAuthorAppService AuthorAppService +@inject AbpBlazorMessageLocalizerHelper LH @@ -917,68 +919,104 @@ Create a new Razor Component Page, `/Pages/Authors.razor`, in the `Acme.BookStor - - @L["NewAuthor"] - - - - - @L["Name"] - - - - @L["BirthDate"] - - - - @L["ShortBio"] - - - - - - - +
+ + @L["NewAuthor"] + + + + + + + @L["Name"] + + + + + + + + + @L["BirthDate"] + + + + + @L["ShortBio"] + + + + + + + + + + + + + +
- - @EditingAuthor.Name - - - - - @L["Name"] - - - - @L["BirthDate"] - - - - @L["ShortBio"] - - - - - - - +
+ + @EditingAuthor.Name + + + + + + + @L["Name"] + + + + + + + + + @L["BirthDate"] + + + + + @L["ShortBio"] + + + + + + + + + + + + + +
```` @@ -1025,6 +1063,10 @@ namespace Acme.BookStore.Blazor.Pages private Modal CreateAuthorModal { get; set; } private Modal EditAuthorModal { get; set; } + private Validations CreateValidationsRef; + + private Validations EditValidationsRef; + public Authors() { NewAuthor = new CreateAuthorDto(); @@ -1079,6 +1121,8 @@ namespace Acme.BookStore.Blazor.Pages private void OpenCreateAuthorModal() { + CreateValidationsRef?.ClearAll(); + NewAuthor = new CreateAuthorDto(); CreateAuthorModal.Show(); } @@ -1090,6 +1134,8 @@ namespace Acme.BookStore.Blazor.Pages private void OpenEditAuthorModal(AuthorDto author) { + EditValidationsRef?.ClearAll(); + EditingAuthorId = author.Id; EditingAuthor = ObjectMapper.Map(author); EditAuthorModal.Show(); @@ -1114,16 +1160,22 @@ namespace Acme.BookStore.Blazor.Pages private async Task CreateAuthorAsync() { - await AuthorAppService.CreateAsync(NewAuthor); - await GetAuthorsAsync(); - CreateAuthorModal.Hide(); + if (CreateValidationsRef?.ValidateAll() ?? true) + { + await AuthorAppService.CreateAsync(NewAuthor); + await GetAuthorsAsync(); + CreateAuthorModal.Hide(); + } } private async Task UpdateAuthorAsync() { - await AuthorAppService.UpdateAsync(EditingAuthorId, EditingAuthor); - await GetAuthorsAsync(); - EditAuthorModal.Hide(); + if (EditValidationsRef?.ValidateAll() ?? true) + { + await AuthorAppService.UpdateAsync(EditingAuthorId, EditingAuthor); + await GetAuthorsAsync(); + EditAuthorModal.Hide(); + } } } }