|
@@ -55,6 +55,11 @@ namespace InABox.Core
|
|
|
{
|
|
|
protected TPoster Poster;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// A set of fragments that also need to be saved along with the <see cref="IPostable"/> entities.
|
|
|
+ /// </summary>
|
|
|
+ private Dictionary<Type, List<IPostableFragment>> Fragments = new Dictionary<Type, List<IPostableFragment>>();
|
|
|
+
|
|
|
public PosterEngine()
|
|
|
{
|
|
|
Poster = CreatePoster();
|
|
@@ -113,6 +118,17 @@ namespace InABox.Core
|
|
|
new Client<TPostable>().Save(entities, "Post failed by user.");
|
|
|
}
|
|
|
|
|
|
+ protected void AddFragment(IPostableFragment fragment)
|
|
|
+ {
|
|
|
+ var type = fragment.GetType();
|
|
|
+ if(!Fragments.TryGetValue(type, out var fragments))
|
|
|
+ {
|
|
|
+ fragments = new List<IPostableFragment>();
|
|
|
+ Fragments[type] = fragments;
|
|
|
+ }
|
|
|
+ fragments.Add(fragment);
|
|
|
+ }
|
|
|
+
|
|
|
public bool Process(IDataModel<TPostable> model)
|
|
|
{
|
|
|
if (!BeforePost(model))
|
|
@@ -150,7 +166,13 @@ namespace InABox.Core
|
|
|
post.PostedStatus = PostedStatus.Posted;
|
|
|
post.PostedNote = "";
|
|
|
}
|
|
|
+
|
|
|
new Client<TPostable>().Save(entities, "Posted by user.");
|
|
|
+
|
|
|
+ foreach(var (type, fragments) in Fragments)
|
|
|
+ {
|
|
|
+ Client.Create(type).Save(fragments.Cast<Entity>(), "");
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|