private TSBExchangeTransaction CloneTransaction(TSBExchangeTransaction src, bool setZero = false)
        {
            if (null == src)
            {
                return(null);
            }
            var dst = new TSBExchangeTransaction();

            CopyTransaction(src, dst, setZero);
            return(dst);
        }
        public NDbResult <List <TSBExchangeTransaction> > GetTSBExchangeTransactions(
            [FromBody] Search.Exchanges.Transactions.Filter value)
        {
            NDbResult <List <TSBExchangeTransaction> > result;

            if (null == value)
            {
                result = new NDbResult <List <TSBExchangeTransaction> >();
                result.ParameterIsNull();
            }
            else
            {
                result = TSBExchangeTransaction.GetTransactions(value.TSB, value.GroupId);
            }
            return(result);
        }
Esempio n. 3
0
        private static TSBCreditTransaction CloneTransaction(TSBExchangeTransaction value, bool isMinuis = false)
        {
            int sign = (isMinuis) ? -1 : 1;
            TSBCreditTransaction inst = new TSBCreditTransaction();

            // Common
            inst.TransactionDate = value.TransactionDate;
            inst.GroupId         = value.GroupId;
            // TSB.
            inst.TSBId     = value.TSBId;
            inst.TSBNameEN = value.TSBNameEN;
            inst.TSBNameTH = value.TSBNameTH;
            // Supervisor.
            inst.SupervisorId     = value.UserId;
            inst.SupervisorNameEN = value.FullNameEN;
            inst.SupervisorNameTH = value.FullNameTH;
            // Amount
            inst.AmountST25    = sign * value.AmountST25;
            inst.AmountST50    = sign * value.AmountST50;
            inst.AmountBHT1    = sign * value.AmountBHT1;
            inst.AmountBHT2    = sign * value.AmountBHT2;
            inst.AmountBHT5    = sign * value.AmountBHT5;
            inst.AmountBHT10   = sign * value.AmountBHT10;
            inst.AmountBHT20   = sign * value.AmountBHT20;
            inst.AmountBHT50   = sign * value.AmountBHT50;
            inst.AmountBHT100  = sign * value.AmountBHT100;
            inst.AmountBHT500  = sign * value.AmountBHT500;
            inst.AmountBHT1000 = sign * value.AmountBHT1000;
            // Count - no need because auto calc in model class.

            /*
             * inst.CountST25 = sign * value.CountST25;
             * inst.CountST50 = sign * value.CountST50;
             * inst.CountBHT1 = sign * value.CountBHT1;
             * inst.CountBHT2 = sign * value.CountBHT2;
             * inst.CountBHT5 = sign * value.CountBHT5;
             * inst.CountBHT10 = sign * value.CountBHT10;
             * inst.CountBHT20 = sign * value.CountBHT20;
             * inst.CountBHT50 = sign * value.CountBHT50;
             * inst.CountBHT100 = sign * value.CountBHT100;
             * inst.CountBHT500 = sign * value.CountBHT500;
             * inst.CountBHT1000 = sign * value.CountBHT1000;
             */

            return(inst);
        }
Esempio n. 4
0
        /// <summary>
        /// Save TSB Exchange Group.
        /// </summary>
        /// <param name="value">The TSBExchangeGroup instance.</param>
        /// <returns>Returns save TSBExchangeGroup instance.</returns>
        public static NDbResult <TSBExchangeGroup> SaveTSBExchangeGroup(TSBExchangeGroup value)
        {
            var result          = new NDbResult <TSBExchangeGroup>();
            SQLiteConnection db = Default;

            if (null == db)
            {
                result.DbConenctFailed();
                return(result);
            }
            if (null == value)
            {
                result.ParameterIsNull();
            }
            if (value.GroupId == Guid.Empty)
            {
                value.GroupId = Guid.NewGuid();
            }
            result = Save(value);             // save group.

            // save each transaction
            if (null != value.Request)
            {
                value.Request.GroupId         = value.GroupId;
                value.Request.TransactionType = TSBExchangeTransaction.TransactionTypes.Request;
                TSBExchangeTransaction.Save(value.Request);
            }
            if (null != value.Approve)
            {
                value.Approve.GroupId         = value.GroupId;
                value.Approve.TransactionType = TSBExchangeTransaction.TransactionTypes.Approve;
                TSBExchangeTransaction.Save(value.Approve);
            }
            if (null != value.Received)
            {
                bool updateCredit = (value.Received.TransactionId == 0);                 // add new.
                value.Received.GroupId         = value.GroupId;
                value.Received.TransactionType = TSBExchangeTransaction.TransactionTypes.Received;
                TSBExchangeTransaction.Save(value.Received);
                if (updateCredit)
                {
                    TSBCreditTransaction tran = CloneTransaction(value.Received);
                    // Set property here.
                    tran.TransactionType = TSBCreditTransaction.TransactionTypes.Received;
                    // Additional keep only received
                    tran.AdditionalBHT = value.Received.AdditionalBHT;
                    // Save.
                    TSBCreditTransaction.Save(tran);
                }
            }
            if (null != value.Exchange)
            {
                bool updateCredit = (value.Exchange.TransactionId == 0);                 // add new.
                value.Exchange.GroupId         = value.GroupId;
                value.Exchange.TransactionType = TSBExchangeTransaction.TransactionTypes.Exchange;
                TSBExchangeTransaction.Save(value.Exchange);
                if (updateCredit)
                {
                    TSBCreditTransaction tran = CloneTransaction(value.Exchange, true);
                    // Set property here.
                    tran.TransactionType = TSBCreditTransaction.TransactionTypes.Received;
                    // Save.
                    TSBCreditTransaction.Save(tran);
                }
            }
            if (null != value.Return)
            {
                value.Return.GroupId         = value.GroupId;
                value.Return.TransactionType = TSBExchangeTransaction.TransactionTypes.Return;
                TSBExchangeTransaction.Save(value.Return);
            }

            return(result);
        }
        private void CopyTransaction(TSBExchangeTransaction src, TSBExchangeTransaction dst, bool setZero = false)
        {
            if (null == src || null == dst)
            {
                return;
            }
            // Transaction
            dst.GroupId         = src.GroupId;
            dst.TransactionDate = DateTime.Now;
            // Amount
            dst.AmountST25    = (!setZero) ? src.AmountST25 : decimal.Zero;
            dst.AmountST50    = (!setZero) ? src.AmountST50 : decimal.Zero;
            dst.AmountBHT1    = (!setZero) ? src.AmountBHT1 : decimal.Zero;
            dst.AmountBHT2    = (!setZero) ? src.AmountBHT2 : decimal.Zero;
            dst.AmountBHT5    = (!setZero) ? src.AmountBHT5 : decimal.Zero;
            dst.AmountBHT10   = (!setZero) ? src.AmountBHT10 : decimal.Zero;
            dst.AmountBHT20   = (!setZero) ? src.AmountBHT20 : decimal.Zero;
            dst.AmountBHT50   = (!setZero) ? src.AmountBHT50 : decimal.Zero;
            dst.AmountBHT100  = (!setZero) ? src.AmountBHT100 : decimal.Zero;
            dst.AmountBHT500  = (!setZero) ? src.AmountBHT500 : decimal.Zero;
            dst.AmountBHT1000 = (!setZero) ? src.AmountBHT1000 : decimal.Zero;
            // Count - no need because auto calc in model class.

            /*
             * dst.CountST25 = (!setZero) ? src.CountST25 : 0;
             * dst.CountST50 = (!setZero) ? src.CountST50 : 0;
             * dst.CountBHT1 = (!setZero) ? src.CountBHT1 : 0;
             * dst.CountBHT2 = (!setZero) ? src.CountBHT2 : 0;
             * dst.CountBHT5 = (!setZero) ? src.CountBHT5 : 0;
             * dst.CountBHT10 = (!setZero) ? src.CountBHT10 : 0;
             * dst.CountBHT20 = (!setZero) ? src.CountBHT20 : 0;
             * dst.CountBHT50 = (!setZero) ? src.CountBHT50 : 0;
             * dst.CountBHT100 = (!setZero) ? src.CountBHT100 : 0;
             * dst.CountBHT500 = (!setZero) ? src.CountBHT500 : 0;
             * dst.CountBHT1000 = (!setZero) ? src.CountBHT1000 : 0;
             */
            // TSB
            dst.TSBId     = src.TSBId;
            dst.TSBNameEN = src.TSBNameEN;
            dst.TSBNameTH = src.TSBNameTH;
            // User
            dst.UserId     = src.UserId;
            dst.FullNameEN = src.FullNameEN;
            dst.FullNameTH = src.FullNameTH;
            // Amount
            dst.ExchangeBHT   = (!setZero) ? src.ExchangeBHT : decimal.Zero;
            dst.BorrowBHT     = (!setZero) ? src.BorrowBHT : decimal.Zero;
            dst.AdditionalBHT = (!setZero) ? src.AdditionalBHT : decimal.Zero;
            // Period
            dst.PeriodBegin = src.PeriodBegin;
            dst.PeriodEnd   = src.PeriodEnd;

            /*
             * if (dst.BorrowBHT > decimal.Zero)
             * {
             *  dst.PeriodBegin = src.PeriodBegin;
             *  dst.PeriodEnd = src.PeriodEnd;
             * }
             * else
             * {
             *  dst.PeriodBegin = new DateTime?();
             *  dst.PeriodEnd = new DateTime?();
             * }
             */
        }