From bc6dce105ba93323d444367348e3de35cff795c8 Mon Sep 17 00:00:00 2001 From: "Mariana R. Santos" Date: Thu, 23 Jan 2025 11:01:27 +0100 Subject: [PATCH] Update inspections after isar mission accepted --- backend/api/Services/MissionRunService.cs | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/api/Services/MissionRunService.cs b/backend/api/Services/MissionRunService.cs index 287b9d1a..8785066e 100644 --- a/backend/api/Services/MissionRunService.cs +++ b/backend/api/Services/MissionRunService.cs @@ -321,6 +321,27 @@ public async Task Update(MissionRun missionRun) DetachTracking(context, missionRun!); } + public async Task UpdateWithInspections(MissionRun missionRun) + { + if (missionRun.Robot is not null) + { + context.Entry(missionRun.Robot).State = EntityState.Unchanged; + } + if (missionRun.InspectionArea is not null) + { + context.Entry(missionRun.InspectionArea).State = EntityState.Unchanged; + } + + var entry = context.Update(missionRun); + await ApplyDatabaseUpdate(missionRun.InspectionArea?.Installation); + _ = signalRService.SendMessageAsync( + "Mission run updated", + missionRun?.InspectionArea?.Installation, + missionRun != null ? new MissionRunResponse(missionRun) : null + ); + DetachTracking(context, missionRun!); + } + public async Task Delete(string id) { var missionRun = await GetMissionRunsWithSubModels() @@ -812,8 +833,12 @@ await ReadById(missionRunId, readOnly: true) { var task = missionRun.GetTaskByIsarId(isarTask.IsarTaskId); task?.UpdateWithIsarInfo(isarTask); + var updatedTask = missionRun.Tasks.FirstOrDefault( + (task) => task.IsarTaskId == isarTask.IsarTaskId + ); + updatedTask = task; } - await Update(missionRun); + await UpdateWithInspections(missionRun); return missionRun; } }