SetoutStore.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Comal.Classes;
  2. using System;
  3. using InABox.Core;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Syncfusion.Pdf.Parsing;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Drawing.Imaging;
  10. namespace Comal.Stores
  11. {
  12. public class SetoutStore : BaseStore<Setout>
  13. {
  14. protected override void AfterSave(Setout entity)
  15. {
  16. if (entity.Group.ID != Guid.Empty)
  17. {
  18. var table = Provider.Query<SetoutGroup>(new Filter<SetoutGroup>(x => x.ID).IsEqualTo(entity.Group.ID)
  19. .And(x => x.OptimizationDocument.ID).IsNotEqualTo(Guid.Empty),
  20. new Columns<SetoutGroup>(x => x.OptimizationDocument.ID));
  21. if (!table.Rows.Any())
  22. return;
  23. var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
  24. if (docID == Guid.Empty)
  25. return;
  26. List<Guid> ids = new List<Guid>();
  27. var docsTable = Provider.Query<SetoutDocument>(
  28. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(entity.ID),
  29. new Columns<SetoutDocument>(x => x.DocumentLink.ID)
  30. );
  31. foreach (var row in docsTable.Rows)
  32. ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
  33. if (!ids.Contains(docID))
  34. {
  35. var setoutdoc = new SetoutDocument();
  36. setoutdoc.EntityLink.ID = entity.ID;
  37. setoutdoc.DocumentLink.ID = docID;
  38. FindSubStore<SetoutDocument>().Save(setoutdoc, "Added optimsation document from Group");
  39. }
  40. }
  41. base.AfterSave(entity);
  42. }
  43. protected override void BeforeDelete(Setout entity)
  44. {
  45. UnlinkTrackingKanban<SetoutKanban, Setout, SetoutLink>(entity);
  46. }
  47. }
  48. }