🐛 Fix poll controller agian...
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user