From 1eb48c0f6b72ffffe88db159218ce5aadcb031e8 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 6 Aug 2024 08:25:44 -0700 Subject: [PATCH] Renaming Query should not clone Fix #16526 --- .../OrchardCore.Queries/Controllers/AdminController.cs | 6 ++++-- .../ViewModels/QueriesCreateViewModel.cs | 3 +++ .../OrchardCore.Queries/ViewModels/QueriesEditViewModel.cs | 6 ++++++ .../OrchardCore.Queries/Views/Admin/Edit.cshtml | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs index f6616cca816..c3fb7118456 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs @@ -190,6 +190,7 @@ public async Task Edit(string id) var model = new QueriesEditViewModel { + QueryId = id, Name = query.Name, Editor = await _displayManager.BuildEditorAsync(query, _updateModelAccessor.ModelUpdater, false) }; @@ -206,12 +207,12 @@ public async Task EditPost(QueriesEditViewModel model) return Forbid(); } - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.QueryId)) { return BadRequest(); } - var query = await _queryManager.GetQueryAsync(model.Name); + var query = await _queryManager.GetQueryAsync(model.QueryId); if (query == null) { @@ -222,6 +223,7 @@ public async Task EditPost(QueriesEditViewModel model) if (ModelState.IsValid) { + await _queryManager.DeleteQueryAsync(model.QueryId); await _queryManager.UpdateAsync(query); await _notifier.SuccessAsync(H["Query updated successfully."]); diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesCreateViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesCreateViewModel.cs index c09fd5a6aa7..5dd42d1a8b1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesCreateViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesCreateViewModel.cs @@ -1,8 +1,11 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding; + namespace OrchardCore.Queries.ViewModels; public class QueriesCreateViewModel { public string SourceName { get; set; } + [BindNever] public dynamic Editor { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesEditViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesEditViewModel.cs index 5c2d26b957f..2bdf6c31160 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesEditViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/ViewModels/QueriesEditViewModel.cs @@ -1,8 +1,14 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding; + namespace OrchardCore.Queries.ViewModels; public class QueriesEditViewModel { + public string QueryId { get; set; } + + [BindNever] public string Name { get; set; } + [BindNever] public dynamic Editor { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Queries/Views/Admin/Edit.cshtml index a5c3c58dadb..4251cb02f62 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Views/Admin/Edit.cshtml @@ -17,5 +17,5 @@ } - +