🐛 Trying to fix poll update

This commit is contained in:
2025-08-06 02:15:40 +08:00
parent 5bb9ed5f04
commit e50ce2f515

View File

@@ -199,14 +199,13 @@ public class PollController(AppDatabase db, PollService polls, PublisherService
if (request.Questions != null) if (request.Questions != null)
{ {
// Remove existing questions // Remove existing questions
db.PollQuestions.RemoveRange(poll.Questions); poll.Questions.Clear();
// Add new questions // Add new questions
poll.Questions = request.Questions.Select(q => q.ToQuestion()).ToList(); poll.Questions.AddRange(request.Questions.Select(q => q.ToQuestion()));
} }
polls.ValidatePoll(poll); polls.ValidatePoll(poll);
poll.UpdatedAt = SystemClock.Instance.GetCurrentInstant();
await db.SaveChangesAsync(); await db.SaveChangesAsync();
// Commit the transaction if all operations succeed // Commit the transaction if all operations succeed
@@ -271,4 +270,4 @@ public class PollController(AppDatabase db, PollService polls, PublisherService
return StatusCode(500, "An error occurred while deleting the poll... " + ex.Message); return StatusCode(500, "An error occurred while deleting the poll... " + ex.Message);
} }
} }
} }