Sfoglia il codice sorgente

Added BeforePost method to MYOB posters

Kenric Nugteren 1 anno fa
parent
commit
6135a72090

+ 2 - 0
InABox.Core/DataModel/DataModel.cs

@@ -80,6 +80,8 @@ namespace InABox.Core
     {
         IEnumerable<DataTable> DefaultTables { get; }
 
+        IEnumerable<KeyValuePair<string, DataModel.DataModelTable>> ModelTables { get; }
+
         void AddTable(string alias, CoreTable table, bool isdefault = false);
 
         void AddTable(Type type, CoreTable table, bool isdefault = false, string? alias = null);

+ 52 - 0
InABox.Core/Utils/Result.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Text;
+
+namespace InABox.Core
+{
+    public static class Result
+    {
+        public static Result<T, E> Ok<T, E>(T value)
+        {
+            return new Result<T, E>(value);
+        }
+        public static Result<T, E> Error<T, E>(E error)
+        {
+            return new Result<T, E>(error);
+        }
+    }
+
+    public class Result<T, E>
+    {
+        public enum Status
+        {
+            Ok,
+            Error
+        }
+
+        private T _value;
+        private E _error;
+        private Status _status;
+
+        public Result(T value)
+        {
+            _value = value;
+            _error = default;
+            _status = Status.Ok;
+        }
+        public Result(E error)
+        {
+            _value = default;
+            _error = error;
+            _status = Status.Error;
+        }
+
+        public bool Get([NotNullWhen(true)][MaybeNull] out T value, [NotNullWhen(false)][MaybeNull] out E error)
+        {
+            value = _value;
+            error = _error;
+            return _status == Status.Ok;
+        }
+    }
+}

+ 2 - 0
InABox.Poster.MYOB/IMYOBPoster.cs

@@ -13,5 +13,7 @@ public interface IMYOBPoster<TPostable> : IPoster<TPostable, MYOBPosterSettings>
 {
     public MYOBConnectionData ConnectionData { get; set; }
 
+    bool BeforePost(IDataModel<TPostable> model);
+
     IPostResult<TPostable> Process(IDataModel<TPostable> model);
 }

+ 1 - 1
InABox.Poster.MYOB/MYOBPosterEngine.cs

@@ -48,7 +48,7 @@ public partial class MYOBPosterEngine<TPostable> :
 
     public override bool BeforePost(IDataModel<TPostable> model)
     {
-        return true;
+        return Poster.BeforePost(model);
     }
 
     public static bool GetAuthorisationCode(IApiConfiguration config, out string? code)