Move around response.redirect calls

This commit is contained in:
Laura Hausmann 2023-04-08 14:49:30 +02:00
parent f9696e17a7
commit d390bd26fb
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 4 additions and 7 deletions

View file

@ -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("/");
}
}

View file

@ -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("/");
}
}
}