Пример #1
0
            public TSBCreditTransaction ToTSBCreditTransaction()
            {
                TSBCreditTransaction inst = new TSBCreditTransaction();

                this.AssignTo(inst); // set all properties to new instance.
                return(inst);
            }
Пример #2
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);
        }
Пример #3
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);
        }