From d390bd26fb4e562c7bea0b265944a398ceb7a534 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 8 Apr 2023 14:49:30 +0200 Subject: [PATCH] Move around response.redirect calls --- Pages/Edit.cshtml.cs | 4 ++-- Pages/Index.cshtml.cs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Pages/Edit.cshtml.cs b/Pages/Edit.cshtml.cs index f016a2a..bde0738 100644 --- a/Pages/Edit.cshtml.cs +++ b/Pages/Edit.cshtml.cs @@ -9,6 +9,8 @@ public class EditModel : PageModel { public void OnGet() { } public async void OnPost() { + Response.Redirect("/"); + await using var db = new DatabaseContext(); var bot = db.Bots.First(p => p.Id == int.Parse(Request.RouteValues["id"]!.ToString()!)); @@ -30,7 +32,5 @@ public class EditModel : PageModel { await db.SaveChangesAsync(); Task.WhenAny(Task.Run(() => BotOrchestrator.AddBot(bot)), Task.Delay(500)).Wait(); } - - Response.Redirect("/"); } } diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs index e4c5b9a..0572784 100644 --- a/Pages/Index.cshtml.cs +++ b/Pages/Index.cshtml.cs @@ -8,6 +8,8 @@ public class IndexModel : PageModel { public void OnGet() { } public async void OnPost() { + Response.Redirect("/"); + await using var db = new DatabaseContext(); if (Request.Form["action"] == "add_bot") { var bot = new Backend.Database.Tables.Bot { @@ -21,17 +23,12 @@ public class IndexModel : PageModel { db.Add(bot); await db.SaveChangesAsync(); await Task.WhenAny(Task.Run(() => BotOrchestrator.AddBot(bot)), Task.Delay(500)); - Response.Redirect("/"); } else if (Request.Form["action"] == "delete_bot") { var bot = await db.Bots.FindAsync(int.Parse(Request.Form["bot_id"]!)); BotOrchestrator.DelBot(bot!); db.Remove(bot!); await db.SaveChangesAsync(); - Response.Redirect("/"); - } - else { - Response.Redirect("/"); } } }