From e47fc64c335516ed948f79e69d4184bc7d2ad2a4 Mon Sep 17 00:00:00 2001 From: Grayson Walker Date: Mon, 16 Aug 2021 14:37:11 -0400 Subject: [PATCH] profiles validation --- .../Modules/Admin/Profiles/Edit.razor | 227 +++++++++--------- 1 file changed, 120 insertions(+), 107 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor index 0a6ce896..afbbb683 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor @@ -5,86 +5,90 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer -
-
- -
- +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -@SharedLocalizer["Cancel"] -@if (PageState.QueryString.ContainsKey("id")) -{
-
- -} + + @SharedLocalizer["Cancel"] + @if (PageState.QueryString.ContainsKey("id")) + { +
+
+ + } + @code { private int _profileid = -1; + private ElementReference form; + private bool validated = false; private string _name = string.Empty; private string _title = string.Empty; private string _description = string.Empty; @@ -140,45 +144,54 @@ private async Task SaveProfile() { - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - Profile profile; - if (_profileid != -1) + try { - profile = await ProfileService.GetProfileAsync(_profileid); - } - else - { - profile = new Profile(); - } + Profile profile; + if (_profileid != -1) + { + profile = await ProfileService.GetProfileAsync(_profileid); + } + else + { + profile = new Profile(); + } - profile.SiteId = PageState.Site.SiteId; - profile.Name = _name; - profile.Title = _title; - profile.Description = _description; - profile.Category = _category; - profile.ViewOrder = int.Parse(_vieworder); - profile.MaxLength = int.Parse(_maxlength); - profile.DefaultValue = _defaultvalue; - profile.Options = _options; - profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired)); - profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate)); - if (_profileid != -1) - { - profile = await ProfileService.UpdateProfileAsync(profile); - } - else - { - profile = await ProfileService.AddProfileAsync(profile); - } + profile.SiteId = PageState.Site.SiteId; + profile.Name = _name; + profile.Title = _title; + profile.Description = _description; + profile.Category = _category; + profile.ViewOrder = int.Parse(_vieworder); + profile.MaxLength = int.Parse(_maxlength); + profile.DefaultValue = _defaultvalue; + profile.Options = _options; + profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired)); + profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate)); + if (_profileid != -1) + { + profile = await ProfileService.UpdateProfileAsync(profile); + } + else + { + profile = await ProfileService.AddProfileAsync(profile); + } - await logger.LogInformation("Profile Saved {Profile}", profile); - NavigationManager.NavigateTo(NavigateUrl()); + await logger.LogInformation("Profile Saved {Profile}", profile); + NavigationManager.NavigateTo(NavigateUrl()); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message); + AddModuleMessage(Localizer["Error.Profile.Save"], MessageType.Error); + } } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message); - AddModuleMessage(Localizer["Error.Profile.Save"], MessageType.Error); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } }