| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | 
							- using Comal.Classes;
 
- using System;
 
- using InABox.Core;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using Syncfusion.Pdf.Parsing;
 
- using System.Drawing;
 
- using System.IO;
 
- using System.Drawing.Imaging;
 
- using InABox.Database;
 
- namespace Comal.Stores
 
- {
 
-     public class SetoutStore : BaseStore<Setout>
 
-     {
 
-         protected override void AfterSave(Setout entity)
 
-         {
 
-             if (entity.Group.ID != Guid.Empty)
 
-             {
 
-                 var table = Provider.Query<SetoutGroup>(new Filter<SetoutGroup>(x => x.ID).IsEqualTo(entity.Group.ID)
 
-                     .And(x => x.OptimizationDocument.ID).IsNotEqualTo(Guid.Empty),
 
-                     new Columns<SetoutGroup>(x => x.OptimizationDocument.ID));
 
-                 if (!table.Rows.Any())
 
-                     return;
 
-                 var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
 
-                 UpdateOptimisationDocument(FindSubStore<SetoutDocument>, entity, docID);
 
-             }
 
-             base.AfterSave(entity);
 
-         }
 
-         /// <summary>
 
-         /// Update the optimisation document ID for a setout. The setout must have a non-empty <see cref="Entity.ID"/>.
 
-         /// </summary>
 
-         /// <param name="docStore"></param>
 
-         /// <param name="setout">Setout with non-empty <see cref="Entity.ID"/></param>
 
-         /// <param name="optimisationDocumentID"></param>
 
-         public static void UpdateOptimisationDocument(Func<IStore<SetoutDocument>> docStore, Setout setout, Guid optimisationDocumentID)
 
-         {
 
-             if (optimisationDocumentID == Guid.Empty) return;
 
-             var ids = new List<Guid>();
 
-             var docsTable = DbFactory.Provider.Query<SetoutDocument>(
 
-                 new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setout.ID),
 
-                 new Columns<SetoutDocument>(x => x.DocumentLink.ID)
 
-                 );
 
-             foreach (var row in docsTable.Rows)
 
-                 ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
 
-             if (!ids.Contains(optimisationDocumentID))
 
-             {
 
-                 var setoutdoc = new SetoutDocument();
 
-                 setoutdoc.EntityLink.ID = setout.ID;
 
-                 setoutdoc.DocumentLink.ID = optimisationDocumentID;
 
-                 docStore().Save(setoutdoc, "Added optimsation document from Group");
 
-             }
 
-         }
 
-         protected override void BeforeDelete(Setout entity)
 
-         {
 
-             UnlinkTrackingKanban<SetoutKanban, Setout, SetoutLink>(entity);
 
-         }
 
-     }
 
- }
 
 
  |