Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Npgsql;
using TeachingRecordSystem.Core.DataStore.Postgres;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
using TeachingRecordSystem.Core.Models.SupportTasks;
Expand Down Expand Up @@ -36,7 +35,6 @@ public async Task<IActionResult> OnPostAsync()

var supportTask = new SupportTask()
{
SupportTaskReference = SupportTask.GenerateSupportTaskReference(),
CreatedOn = clock.UtcNow,
UpdatedOn = clock.UtcNow,
SupportTaskType = SupportTaskType.ConnectOneLoginUser,
Expand Down Expand Up @@ -65,19 +63,7 @@ await dbContext.AddEventAndBroadcastAsync(new LegacyEvents.SupportTaskCreatedEve
SupportTask = EventModels.SupportTask.FromModel(supportTask)
});

while (true)
{
try
{
await dbContext.SaveChangesAsync();
break;
}
catch (Exception ex) when (ex.InnerException is PostgresException postgresException && postgresException.SqlState == PostgresErrorCodes.UniqueViolation)
{
supportTask.SupportTaskReference = SupportTask.GenerateSupportTaskReference();
continue;
}
}
await dbContext.SaveChangesAsync();

await JourneyInstance.UpdateStateAsync(state => state.HasPendingSupportRequest = true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Configure(EntityTypeBuilder<SupportTask> builder)
builder.ToTable("support_tasks");
builder.HasKey(p => p.SupportTaskReference);
builder.HasQueryFilter(q => EF.Property<DateTime?>(q, nameof(SupportTask.DeletedOn)) == null);
builder.Property(p => p.SupportTaskReference).HasMaxLength(16);
builder.Property(p => p.SupportTaskReference).HasMaxLength(16).HasDefaultValueSql("'TRS-' || nextval('support_task_reference')::text");
builder.HasOne(t => t.Person).WithMany().HasForeignKey(p => p.PersonId).HasConstraintName("fk_support_tasks_person");
builder.HasIndex(t => t.OneLoginUserSubject);
builder.HasIndex(t => t.PersonId);
Expand Down
Loading
Loading