Skip to content

Commit 9d2bcce

Browse files
CopilotMikeAlhayek
andcommitted
Address code review feedback - simplify delete operations
Co-authored-by: MikeAlhayek <24724371+MikeAlhayek@users.noreply.github.com>
1 parent 214e5da commit 9d2bcce

4 files changed

Lines changed: 13 additions & 16 deletions

File tree

src/Core/CrestApps.OrchardCore.AI.Core/Services/DefaultAIChatSessionManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,14 @@ public async Task<int> DeleteAllAsync(string profileId)
169169
collection: AIConstants.CollectionName)
170170
.ListAsync();
171171

172+
var totalDeleted = 0;
173+
172174
foreach (var session in sessions)
173175
{
174176
_session.Delete(session, collection: AIConstants.CollectionName);
177+
totalDeleted++;
175178
}
176179

177-
return sessions.Count;
180+
return totalDeleted;
178181
}
179182
}

src/Modules/CrestApps.OrchardCore.AI.Chat/Controllers/AdminController.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public IActionResult Chat(string profileId)
209209
=> RedirectToAction(nameof(Index), new { profileId });
210210

211211
[Admin("ai/chat/session/delete/{sessionId}", "DeleteChatSession")]
212-
public async Task<IActionResult> Delete(string sessionId, string profileId)
212+
public async Task<IActionResult> Delete(string sessionId)
213213
{
214214
var chatSession = await _sessionManager.FindAsync(sessionId);
215215

@@ -239,12 +239,7 @@ public async Task<IActionResult> Delete(string sessionId, string profileId)
239239
await _notifier.ErrorAsync(H["Unable to delete the chat session."]);
240240
}
241241

242-
if (!string.IsNullOrEmpty(profileId))
243-
{
244-
return RedirectToAction(nameof(History), new { profileId });
245-
}
246-
247-
return RedirectToAction(nameof(Index), new { profileId = chatSession.ProfileId });
242+
return RedirectToAction(nameof(History), new { profileId = chatSession.ProfileId });
248243
}
249244

250245
[HttpPost]

src/Modules/CrestApps.OrchardCore.AI.Chat/Views/AIChatSessionHeader.cshtml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
<div class="card text-bg-theme">
77
<div class="card-body d-flex justify-content-between">
8-
<form asp-action="DeleteAll" asp-controller="Admin" asp-route-profileId="@Model.Session.ProfileId" method="post" class="d-inline">
9-
<button type="submit"
10-
class="btn btn-danger"
11-
data-url-af="RemoveUrl UnsafeUrl">
12-
<i class="fa-solid fa-trash"></i> @T["Delete All History"]
13-
</button>
14-
</form>
8+
<a asp-action="DeleteAll"
9+
asp-controller="Admin"
10+
asp-route-profileId="@Model.Session.ProfileId"
11+
class="btn btn-danger"
12+
data-url-af="RemoveUrl UnsafeUrl">
13+
<i class="fa-solid fa-trash"></i> @T["Delete All History"]
14+
</a>
1515

1616
<div>
1717
<a class="btn btn-secondary me-1" asp-action="Chat" asp-controller="Admin" asp-route-profileId="@Model.Session.ProfileId">

src/Modules/CrestApps.OrchardCore.AI.Chat/Views/AIChatSessionsList.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<a asp-action="Delete"
3636
asp-controller="Admin"
3737
asp-route-sessionId="@session.SessionId"
38-
asp-route-profileId="@Model.ProfileId"
3938
class="btn btn-danger btn-sm"
4039
data-url-af="RemoveUrl UnsafeUrl">@T["Delete"]</a>
4140
</div>

0 commit comments

Comments
 (0)