Просмотр исходного кода

Deleting job scope updates the job default scope if necessary

Kenric Nugteren 1 год назад
Родитель
Сommit
bdd9ee6a47
1 измененных файлов с 19 добавлено и 2 удалено
  1. 19 2
      prs.desktop/Panels/Jobs/JobScopes/JobScopeGrid.cs

+ 19 - 2
prs.desktop/Panels/Jobs/JobScopes/JobScopeGrid.cs

@@ -26,8 +26,25 @@ namespace PRSDesktop
         {
             base.DoReconfigure(options);
             options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.FilterRows);
-            
-            
+        }
+
+        protected override void DeleteItems(params CoreRow[] rows)
+        {
+            base.DeleteItems(rows);
+
+            var row = rows.FirstOrDefault(x => x.Get<JobScope, Guid>(x => x.Job.DefaultScope.ID) == x.Get<JobScope, Guid>(x => x.ID));
+            if (row is not null)
+            {
+                var job = Client.Query(
+                    new Filter<Job>(x => x.ID).IsEqualTo(row.Get<JobScope, Guid>(x => x.Job.ID)),
+                    new Columns<Job>(x => x.ID).Add(x => x.DefaultScope.ID)
+                ).Rows.FirstOrDefault()?.ToObject<Job>();
+                if (job != null)
+                {
+                    job.DefaultScope.ID = row.Get<JobScope, Guid>(x => x.ID);
+                    Client.Save(job, "Updated Default Scope");
+                }
+            }
         }
 
         private BitmapImage? IsDefaultImage(CoreRow? row)