🐛 Fix poll controller agian...

This commit is contained in:
2025-08-06 02:23:22 +08:00
parent e50ce2f515
commit e0ebed7c09

View File

@@ -175,9 +175,6 @@ public class PollController(AppDatabase db, PollService polls, PublisherService
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
var accountId = Guid.Parse(currentUser.Id); var accountId = Guid.Parse(currentUser.Id);
// Start a transaction
await using var transaction = await db.Database.BeginTransactionAsync();
try try
{ {
var poll = await db.Polls var poll = await db.Polls
@@ -206,16 +203,13 @@ public class PollController(AppDatabase db, PollService polls, PublisherService
polls.ValidatePoll(poll); polls.ValidatePoll(poll);
db.Update(poll);
await db.SaveChangesAsync(); await db.SaveChangesAsync();
// Commit the transaction if all operations succeed
await transaction.CommitAsync();
return Ok(poll); return Ok(poll);
} }
catch (Exception ex) catch (Exception ex)
{ {
await transaction.RollbackAsync();
return BadRequest(ex.Message); return BadRequest(ex.Message);
} }
} }