Exemplo n.º 1
0
        /// <summary>
        ///
        /// Save to database a general type of transaction using an existing DbContext (to support transactions)
        /// Save any transaction type to the database
        ///
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="gzTransactionType"></param>
        /// <param name="amount"></param>
        /// <param name="trxYearMonth"></param>
        /// <param name="createdOnUtc">Applicable only for TransferTypeEnum.CreditedPlayingLoss type of transactions</param>
        /// <param name="creditPcntApplied"></param>
        /// <param name="begGmBalance"></param>
        /// <param name="deposits"></param>
        /// <param name="withdrawals"></param>
        /// <param name="gainLoss"></param>
        /// <param name="endGmbalance"></param>
        /// <returns></returns>
        private void SaveDbGzTransaction(
            int customerId, GzTransactionTypeEnum
            gzTransactionType,
            decimal amount,
            string trxYearMonth,
            DateTime createdOnUtc,
            float?creditPcntApplied,
            decimal begGmBalance = 0,
            decimal deposits     = 0,
            decimal withdrawals  = 0,
            decimal gainLoss     = 0,
            decimal endGmbalance = 0)
        {
            /* Used only for playerLoss type of transactions with different uniqueness than other types of transactions:
             *  Only 1 playerloss per player/month is allowed */
            if (gzTransactionType == GzTransactionTypeEnum.CreditedPlayingLoss)
            {
                _db.GzTrxs.AddOrUpdate(

                    t => new { t.CustomerId, t.TypeId, t.YearMonthCtd },
                    new GzTrx {
                    CustomerId = customerId,
                    TypeId     =
                        _db.GzTrxTypes.Where(t => t.Code == gzTransactionType).Select(t => t.Id).FirstOrDefault(),
                    YearMonthCtd = trxYearMonth,
                    Amount       = amount,
                    BegGmBalance = begGmBalance,
                    Deposits     = deposits,
                    Withdrawals  = withdrawals,
                    GmGainLoss   = gainLoss,
                    EndGmBalance = endGmbalance,
                    // Applicable only for TransferTypeEnum.CreditedPlayingLoss type of transactions
                    CreditPcntApplied = creditPcntApplied,
                    // Truncate Millis to avoid mismatch between .net dt <--> mssql dt
                    CreatedOnUtc = createdOnUtc.Truncate(TimeSpan.FromSeconds(1))
                }
                    );
            }
            else
            {
                // Plain insert for non credit loss gztrx
                var newGzTrx =
                    new GzTrx()
                {
                    CustomerId = customerId,
                    TypeId     =
                        _db.GzTrxTypes.Where(t => t.Code == gzTransactionType).Select(t => t.Id).FirstOrDefault(),
                    YearMonthCtd = trxYearMonth,
                    Amount       = amount,
                    // Applicable only for TransferTypeEnum.CreditedPlayingLoss type of transactions
                    CreditPcntApplied = creditPcntApplied,
                    // Truncate Millis to avoid mismatch between .net dt <--> mssql dt
                    CreatedOnUtc = createdOnUtc.Truncate(TimeSpan.FromSeconds(1))
                };
                _db.GzTrxs.Add(newGzTrx);
                _db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// Create any type of transaction from those allowed.
        /// Used along with peer API methods for specialized transactions
        ///
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="gzTransactionType"></param>
        /// <param name="amount"></param>
        /// <param name="trxYearMonth"></param>
        /// <param name="createdOnUtc"></param>
        /// <returns></returns>
        public void SaveDbGzTransaction(int customerId, GzTransactionTypeEnum gzTransactionType, decimal amount, string trxYearMonth, DateTime createdOnUtc)
        {
            if (
                gzTransactionType == GzTransactionTypeEnum.GzFees ||
                gzTransactionType == GzTransactionTypeEnum.FundFee ||
                gzTransactionType == GzTransactionTypeEnum.InvWithdrawal ||
                gzTransactionType == GzTransactionTypeEnum.CreditedPlayingLoss)
            {
                throw new Exception("This type of transaction can be created/updated only by the specialized api of this class" + amount);
            }

            if (amount < 0)
            {
                throw new Exception("Amount must be greater than 0: " + amount);
            }

            SaveDbGzTransaction(customerId, gzTransactionType, amount, trxYearMonth, createdOnUtc, null);

            _db.SaveChanges();
        }