|
|
@@ -1,4 +1,8 @@
|
|
|
using Comal.Classes;
|
|
|
+using System;
|
|
|
+using InABox.Core;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
|
|
|
namespace Comal.Stores
|
|
|
{
|
|
|
@@ -6,6 +10,31 @@ namespace Comal.Stores
|
|
|
{
|
|
|
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),
|
|
|
+ new Columns<SetoutGroup>(x => x.OptimizationDocument.ID));
|
|
|
+ if (table.Rows.Any())
|
|
|
+ {
|
|
|
+ var docID = table.Rows.FirstOrDefault().Get<SetoutGroup, Guid>(x => x.OptimizationDocument.ID);
|
|
|
+ List<Guid> ids = new List<Guid>();
|
|
|
+ var docsTable = Provider.Query<SetoutDocument>(
|
|
|
+ new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(entity.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(docID))
|
|
|
+ {
|
|
|
+ var setoutdoc = new SetoutDocument();
|
|
|
+ setoutdoc.EntityLink.ID = entity.ID;
|
|
|
+ setoutdoc.DocumentLink.ID = docID;
|
|
|
+
|
|
|
+ FindSubStore<SetoutDocument>().Save(setoutdoc, "Added optimsation document from Group");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
base.AfterSave(entity);
|
|
|
}
|
|
|
|