Bladeren bron

Fixing errant writes to Entity.ID

Kenric Nugteren 4 maanden geleden
bovenliggende
commit
d51c523a77

+ 1 - 2
prs.desktop/Components/Spreadsheet/SpreadsheetGrid.cs

@@ -73,9 +73,8 @@ namespace PRSDesktop
             var superceded = row.Get<TSpreadsheet, DateTime>(x => x.Superceded);
             var spreadsheet = new TSpreadsheet()
             {
-                ID = id,
                 Superceded = superceded.IsEmpty() ? DateTime.Now : DateTime.MinValue
-            };
+            }.SetID(id);
             new Client<TSpreadsheet>().Save(spreadsheet, "");
             return true;
         }

+ 2 - 4
prs.desktop/DockPanels/DigitalForms/DigitalFormDockGrid.cs

@@ -180,9 +180,8 @@ public class DigitalFormDockGrid : DynamicGrid<DigitalFormDockModel>
                 {
                     var form = new TEntityForm
                     {
-                        ID = formModel.ID,
                         FormProcessed = formModel.Processed
-                    };
+                    }.SetID(formModel.ID);
                     form.CommitChanges();
                     form.FormProcessed = DateTime.Now;
                     using (new WaitCursor())
@@ -201,9 +200,8 @@ public class DigitalFormDockGrid : DynamicGrid<DigitalFormDockModel>
                 {
                     var form = new TEntityForm
                     {
-                        ID = formModel.ID,
                         FormProcessed = formModel.Processed
-                    };
+                    }.SetID(formModel.ID);
                     form.CommitChanges();
                     form.FormProcessed = DateTime.MinValue;
                     using (new WaitCursor())

+ 1 - 1
prs.desktop/MainWindow.xaml.cs

@@ -3044,7 +3044,7 @@ public partial class MainWindow : IPanelHostControl
             if (changePassword.ShowDialog() == true && changePassword.Password != null)
             {
                 var newUser = new User();
-                newUser.ID = details.User;
+                newUser.SetID(details.User);
 
                 ChangePassword.ChangeUserPassword(newUser, changePassword.Password);
                 new Client<User>().Save(newUser, "Changed Password");

+ 1 - 2
prs.desktop/Panels/DailyReports/DailyReport.xaml.cs

@@ -728,9 +728,8 @@ namespace PRSDesktop
 
             var timesheet = new TimeSheet
             {
-                ID = report.ID,
                 Notes = report.Notes
-            };
+            }.SetID(report.ID);
             new Client<TimeSheet>().Save(timesheet, "", (o, e) => { });
         }
 

+ 2 - 4
prs.desktop/Panels/Delivery/DeliveryPanel.xaml.cs

@@ -158,10 +158,9 @@ namespace PRSDesktop
 
                 var delivery = new Delivery
                 {
-                    ID = Deliveries.SelectedRows.First().Get<Delivery, Guid>(x => x.ID),
                     Number = Deliveries.SelectedRows.First().Get<Delivery, int>(x => x.Number),
                     Completed = DateTime.Now
-                };
+                }.SetID(Deliveries.SelectedRows.First().Get<Delivery, Guid>(x => x.ID));
                 new Client<Delivery>().Save(delivery, "Marked as Completed");
             }
             finally
@@ -205,10 +204,9 @@ namespace PRSDesktop
             {
                 var delivery = new Delivery
                 {
-                    ID = Deliveries.SelectedRows.First().Get<Delivery, Guid>(x => x.ID),
                     Number = Deliveries.SelectedRows.First().Get<Delivery, int>(x => x.Number),
                     Delivered = DateTime.Now
-                };
+                }.SetID(Deliveries.SelectedRows.First().Get<Delivery, Guid>(x => x.ID));
                 delivery.Job.ID = Deliveries.SelectedRows.First().Get<Delivery, Guid>(x => x.Job.ID);
                 new Client<Delivery>().Save(delivery, "Marked as Delivered");
             }

+ 2 - 3
prs.desktop/Panels/Factory/FactoryPanel.xaml.cs

@@ -1029,7 +1029,7 @@ namespace PRSDesktop
                             // If this document is actually the cutting group document, 
                             // redirect any annotations to the cutting group id rather than the setout
                             if (document.DocumentLink.ID == packet.SetoutLink.Group.OptimizationDocument.ID)
-                                document.ID = packet.SetoutLink.Group.ID;
+                                document.SetID(packet.SetoutLink.Group.ID);
                             
                             if (document.DocumentLink != null && document.DocumentLink.FileName != null)
                                 if (document.DocumentLink.FileName.ToLower().EndsWith(".pdf") ||
@@ -2667,8 +2667,7 @@ namespace PRSDesktop
                         false);
                     if (dlg.ShowDialog("Select Area"))
                     {
-                        var location = new StockLocation() { ID = key };
-                        location.CommitChanges();
+                        var location = new StockLocation().SetID(key);
                         location.Area.ID = dlg.IDs().First();
                         new Client<StockLocation>().Save(location,
                             $"Returned From Manufacturing ({_packGrid.Area?.Code})");

+ 2 - 4
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTree.xaml.cs

@@ -1196,9 +1196,7 @@ namespace PRSDesktop
                         documents.Add(doc);
                         if (currentfiles.TryGetValue(filename, out var docID))
                         {
-                            doc.SetObserving(false);
-                            doc.ID = docID;
-                            doc.SetObserving(true);
+                            doc.SetID(docID);
 
                             var linkedfile = jobdocsetfiles.FirstOrDefault(x => x.DocumentLink.ID == doc.ID);
                             if (linkedfile != null)
@@ -1833,7 +1831,7 @@ namespace PRSDesktop
                     foreach (var orphan in orphans)
                     {
                         var update = new JobDocumentSet();
-                        update.ID = orphan.ID;
+                        update.SetID(orphan.ID);
                         update.Parent.ID = Guid.Empty;
                         updates.Add(update);
                     }

+ 1 - 1
prs.desktop/Panels/Manufacturing/ManufacturingPanelColumn.xaml.cs

@@ -418,7 +418,7 @@ namespace PRSDesktop
                 // redirect any annotations to the cutting group id rather than the setout
                 var sgdoc = docs.FirstOrDefault(x => (x.DocumentLink.ID == packet.SetoutLink.Group.OptimizationDocument.ID));
                 if (sgdoc != null)
-                    sgdoc.ID = packet.SetoutLink.Group.ID;
+                    sgdoc.SetID(packet.SetoutLink.Group.ID);
                 
                 var viewer = new DocumentEditor(docs);
                 viewer.ButtonsVisible = true;

+ 3 - 3
prs.desktop/Panels/OrgChart/OrgChartPanel.xaml.cs

@@ -323,7 +323,7 @@ namespace PRSDesktop
                 foreach (var entry in entries)
                 {
                     var update = new Employee();
-                    update.ID = entry.ID;
+                    update.SetID(entry.ID);
                     update.OrgChart.ReportsTo.ID = entry.ParentID;
                     update.OrgChart.Color = entry.Color;
                     update.OrgChart.Visible = entry.Visible;
@@ -342,7 +342,7 @@ namespace PRSDesktop
                 foreach (var entry in entries)
                 {
                     var update = new EmployeePosition();
-                    update.ID = entry.ID;
+                    update.SetID(entry.ID);
                     update.OrgChart.ReportsTo.ID = entry.ParentID;
                     update.OrgChart.Color = entry.Color;
                     update.OrgChart.Visible = entry.Visible;
@@ -361,7 +361,7 @@ namespace PRSDesktop
                 foreach (var entry in entries)
                 {
                     var update = new Role();
-                    update.ID = entry.ID;
+                    update.SetID(entry.ID);
                     update.OrgChart.ReportsTo.ID = entry.ParentID;
                     update.OrgChart.Color = entry.Color;
                     update.OrgChart.Visible = entry.Visible;

+ 3 - 2
prs.shared/Posters/MYOB/BillMYOBPoster.cs

@@ -231,7 +231,8 @@ public class BillMYOBPoster : IMYOBPoster<Bill, BillMYOBPosterSettings>
                     {
                         if(AccountMYOBUtils.GetAccount(ConnectionData, billLine.PurchaseGL.Code).Get(out accountID, out error))
                         {
-                            results.AddFragment(new GLCode { ID = billLine.PurchaseGL.ID, PostedReference = accountID.ToString() });
+                            results.AddFragment(new GLCode { PostedReference = accountID.ToString() }
+                                .SetID(billLine.PurchaseGL.ID));
                         }
                         else
                         {
@@ -271,7 +272,7 @@ public class BillMYOBPoster : IMYOBPoster<Bill, BillMYOBPosterSettings>
                             failed = $"Failed to find TaxCode in MYOB with code {billLine.TaxCode.Code}";
                             break;
                         }
-                        results.AddFragment(new TaxCode { ID = taxCodeID, PostedReference = taxCodeID.ToString() });
+                        results.AddFragment(new TaxCode { PostedReference = taxCodeID.ToString() }.SetID(taxCodeID));
                     }
                     line.TaxCode ??= new();
                     line.TaxCode.UID = taxCodeID;

+ 2 - 2
prs.shared/Posters/MYOB/InvoiceMYOBPoster.cs

@@ -204,7 +204,7 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
                     {
                         if(AccountMYOBUtils.GetAccount(ConnectionData, item.SellGL.Code).Get(out accountID, out error))
                         {
-                            results.AddFragment(new GLCode { ID = item.SellGL.ID, PostedReference = accountID.ToString() });
+                            results.AddFragment(new GLCode { PostedReference = accountID.ToString() }.SetID(item.SellGL.ID));
                         }
                         else
                         {
@@ -236,7 +236,7 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
                             failed = $"Failed to find TaxCode in MYOB with code {item.TaxCode.Code}";
                             break;
                         }
-                        results.AddFragment(new TaxCode { ID = taxCodeID, PostedReference = taxCodeID.ToString() });
+                        results.AddFragment(new TaxCode { PostedReference = taxCodeID.ToString() }.SetID(taxCodeID));
                     }
                     line.TaxCode ??= new();
                     line.TaxCode.UID = taxCodeID;

+ 2 - 2
prs.shared/Posters/MYOB/PurchaseOrderMYOBPoster.cs

@@ -217,7 +217,7 @@ public class PurchaseOrderMYOBPoster : IMYOBPoster<PurchaseOrder, PurchaseOrderM
                     {
                         if(AccountMYOBUtils.GetAccount(ConnectionData, poItem.PurchaseGL.Code).Get(out accountID, out error))
                         {
-                            results.AddFragment(new GLCode { ID = poItem.PurchaseGL.ID, PostedReference = accountID.ToString() });
+                            results.AddFragment(new GLCode { PostedReference = accountID.ToString() }.SetID(poItem.PurchaseGL.ID));
                         }
                         else
                         {
@@ -257,7 +257,7 @@ public class PurchaseOrderMYOBPoster : IMYOBPoster<PurchaseOrder, PurchaseOrderM
                             failed = $"Failed to find TaxCode in MYOB with code {poItem.TaxCode.Code}";
                             break;
                         }
-                        results.AddFragment(new TaxCode { ID = taxCodeID, PostedReference = taxCodeID.ToString() });
+                        results.AddFragment(new TaxCode { PostedReference = taxCodeID.ToString() }.SetID(taxCodeID));
                     }
                     line.TaxCode ??= new();
                     line.TaxCode.UID = taxCodeID;

+ 1 - 2
prs.stores/BaseProductStore.cs

@@ -68,9 +68,8 @@ namespace Comal.Stores
                 {
                     var update = new Product
                     {
-                        ID = info.ProductID,
                         NettCost = Product.CalculateNettCost(info.Strategy, info.BaseCost, compcost)
-                    };
+                    }.SetID(info.ProductID);
                     updates.Add(update);
                 }
             }

+ 1 - 1
prs.stores/GPSTrackerLocationStore.cs

@@ -111,7 +111,7 @@ namespace Comal.Stores
                 if (entity.Tracker.IsValid())
                 {
                     var tracker = new GPSTracker();
-                    tracker.ID = entity.Tracker.ID;
+                    tracker.SetID(entity.Tracker.ID);
                     tracker.Location.Longitude = entity.Location.Longitude;
                     tracker.Location.Latitude = entity.Location.Latitude;
                     tracker.Location.Timestamp = entity.Location.Timestamp;

+ 1 - 4
prs.stores/JobStore.cs

@@ -51,10 +51,7 @@ namespace Comal.Stores
             FindSubStore<JobScope>().Save(scope, "Created automatically on job creation.");
 
             // Save the job again, with a default scope set. We create a lighter job so we're not saving all the same properties over again.
-            var lightJob = new Job
-            {
-                ID = job.ID
-            };
+            var lightJob = new Job().SetID(job.ID);
             lightJob.DefaultScope.ID = scope.ID;
             Provider.Save(lightJob);
 

+ 3 - 1
prs.stores/RequisitionItemStore.cs

@@ -13,7 +13,9 @@ namespace Comal.Stores
                 return;
             
             var requi = new Requisition
-                { ID = entity.RequisitionLink.ID, Filled = entity.RequisitionLink.Filled, Archived = entity.RequisitionLink.Archived };
+            {
+                Filled = entity.RequisitionLink.Filled, Archived = entity.RequisitionLink.Archived
+            }.SetID(entity.RequisitionLink.ID);
 
             UpdateTrackingKanban<RequisitionKanban, Requisition, RequisitionLink>(requi, r =>
             {