SetoutStore.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. new Columns<SetoutGroup>(x => x.OptimizationDocument.ID));
  20. if (table.Rows.Any())
  21. {
  22. var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
  23. List<Guid> ids = new List<Guid>();
  24. var docsTable = Provider.Query<SetoutDocument>(
  25. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(entity.ID),
  26. new Columns<SetoutDocument>(x => x.DocumentLink.ID)
  27. );
  28. foreach (var row in docsTable.Rows)
  29. ids.Add(row.Get<SetoutDocument, Guid>(x => x.DocumentLink.ID));
  30. if (!ids.Contains(docID))
  31. {
  32. var setoutdoc = new SetoutDocument();
  33. setoutdoc.EntityLink.ID = entity.ID;
  34. setoutdoc.DocumentLink.ID = docID;
  35. FindSubStore<SetoutDocument>().Save(setoutdoc, "Added optimsation document from Group");
  36. }
  37. }
  38. }
  39. base.AfterSave(entity);
  40. }
  41. protected override void BeforeDelete(Setout entity)
  42. {
  43. UnlinkTrackingKanban<SetoutKanban, Setout, SetoutLink>(entity);
  44. }
  45. }
  46. }