Esempio n. 1
0
        public bool UpdateAllCheckSumWalletAccountWithEmptyCS(string FromDate, string ToDate)
        {
            var lstWalletAccount = new List <Wallet_Account>();
            var userLogic        = new WalletUserLogic(true);
            var logWallet        = new LogWallet();

            try
            {
                WalletTransactionUow WalletTransactionUnitOfWork = null;
                using (WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
                {
                    var startDate = new DateTime(int.Parse(FromDate.Split('-')[0]), int.Parse(FromDate.Split('-')[1]), int.Parse(FromDate.Split('-')[2]));
                    var toDate    = new DateTime(int.Parse(ToDate.Split('-')[0]), int.Parse(ToDate.Split('-')[1]), int.Parse(ToDate.Split('-')[2]));
                    var diffDate  = toDate.Subtract(startDate).TotalDays;
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Start UpdateAllCheckSumWalletAccountWithEmptyCS", null, "");

                    for (int i = 0; i <= diffDate; i++)
                    {
                        var date = startDate.AddDays(i);
                        lstWalletAccount = WalletTransactionUnitOfWork.GetAllWalletAccountByDateWithoutCS(date);

                        foreach (Wallet_Account walletAcc in lstWalletAccount)
                        {
                            walletAcc.ChecksumAvailable1 = BuildCheckSumAvailable1(walletAcc);
                            walletAcc.ChecksumAvailable2 = BuildCheckSumAvailable2(walletAcc);
                            walletAcc.ChecksumTotal1     = BuildCheckSumTotal1(walletAcc);
                            walletAcc.ChecksumTotal2     = BuildCheckSumTotal2(walletAcc);
                        }
                        WalletTransactionUnitOfWork.DoUpdateMany(lstWalletAccount);
                        logWallet.Log(MethodBase.GetCurrentMethod(), date, null, date.ToString("yyyy-MM-dd") + ": " + lstWalletAccount.Count);
                    }
                    logWallet.Log(MethodBase.GetCurrentMethod(), "End UpdateAllCheckSumWalletAccountWithEmptyCS", null, "");
                }
                return(true);
            }
            catch (Exception ex)
            {
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }
        public bool UpdateCheckSumSnapshot(string pChecksum)
        {
            var lstSnapshots = new List <Wallet_Snapshot>();
            var userLogic    = new WalletUserLogic(true);

            try
            {
                var logWallet = new LogWallet();
                WalletTransactionUow WalletTransactionUnitOfWork = null;
                using (WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
                {
                    lstSnapshots = WalletTransactionUnitOfWork.GetSnapshotByCheckSum(pChecksum);
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Log here 1: " + pChecksum + "|" + lstSnapshots.Count, null, "");
                    var S1 = "";
                    foreach (Wallet_Snapshot walletSnapShot in lstSnapshots)
                    {
                        walletSnapShot.Checksum = BuildCheckSum(walletSnapShot);
                        S1 += (walletSnapShot.ID + walletSnapShot.Account_ID + ConvertUtility.RoundToTwoDecimalPlaces(walletSnapShot.Balance) + walletSnapShot.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + walletSnapShot.Currency_Code + walletSnapShot.Checksum);
                    }
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Log here 2", null, "");
                    var S1Hash = SecurityLogic.GetSha1Hash(S1);
                    logWallet.Log(MethodBase.GetCurrentMethod(), "Log here 3" + S1Hash, null, "");
                    foreach (Wallet_Snapshot Wallet_Snapshot in lstSnapshots)
                    {
                        Wallet_Snapshot.Snapshot = S1Hash;
                    }

                    WalletTransactionUnitOfWork.DoUpdateMany(lstSnapshots).EndTransaction();

                    logWallet.Log(MethodBase.GetCurrentMethod(), "Finish Update UpdateCheckSumSnapshot", null, "");
                }

                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }
Esempio n. 3
0
        public bool UpdateAllCheckSumWalletAccountByUserID(string pUserID)
        {
            var lstWalletAccount = new List <Wallet_Account>();
            var userLogic        = new WalletUserLogic(true);

            try
            {
                var logWallet = new LogWallet();
                WalletTransactionUow WalletTransactionUnitOfWork = null;
                using (WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
                {
                    lstWalletAccount = WalletTransactionUnitOfWork.GetWalletAccountByUserID(pUserID);
                    var flg = false;
                    foreach (Wallet_Account walletAcc in lstWalletAccount)
                    {
                        //if (walletAcc.ChecksumAvailable2 == walletAcc.ChecksumAvailable1)
                        //{
                        walletAcc.ChecksumAvailable1 = BuildCheckSumAvailable1(walletAcc);
                        walletAcc.ChecksumAvailable2 = BuildCheckSumAvailable2(walletAcc);
                        walletAcc.ChecksumTotal1     = BuildCheckSumTotal1(walletAcc);
                        walletAcc.ChecksumTotal2     = BuildCheckSumTotal2(walletAcc);
                        flg = true;
                        //}
                    }
                    if (flg)
                    {
                        WalletTransactionUnitOfWork.DoUpdateMany(lstWalletAccount);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }
        public bool InsertSnapshot(string now)
        {
            var lstRewardAcc      = new List <Wallet_Account_Reward>();
            var lstWalletSnapshot = new List <Wallet_Snapshot>();
            var userLogic         = new WalletUserLogic(true);

            try
            {
                var DateSnapshot = new WalletSnapshotQueryBuilder(new WalletEntities()).GetLatestDateSnapshot().FirstOrDefault().CreateDateSnapshot;
                if (DateSnapshot.Year == int.Parse(now.Split('-')[0]) && DateSnapshot.Month == int.Parse(now.Split('-')[1]) && DateSnapshot.Day == int.Parse(now.Split('-')[2]))
                {
                    return(true);
                }
                WalletTransactionUow WalletTransactionUnitOfWork = null;
                using (WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities()))
                {
                    WalletTransactionUnitOfWork.BeginTransaction();
                    var lstWalletAccount = WalletTransactionUnitOfWork.GetAllWalletAccount().OrderBy(wa => wa.ID);
                    lstRewardAcc = WalletTransactionUnitOfWork.GetAllRewardAccount();
                    string S1 = "";
                    foreach (Wallet_Account walletAcc in lstWalletAccount)
                    {
                        var walletSnapShot = new Wallet_Snapshot();
                        walletSnapShot.ID         = Guid.NewGuid().ToString();
                        walletSnapShot.Account_ID = walletAcc.ID;
                        walletSnapShot.Balance    = walletAcc.Available_Balance;
                        if (lstRewardAcc != null)
                        {
                            var rewardACC = lstRewardAcc.Find(p => p.ID == walletAcc.ID);
                            if (rewardACC != null)
                            {
                                walletSnapShot.Reward_Amount = rewardACC.Reward_Amount;
                            }
                            else
                            {
                                walletSnapShot.Reward_Amount = 0;
                            }
                        }
                        else
                        {
                            walletSnapShot.Reward_Amount = 0;
                        }
                        walletSnapShot.CreateDate         = walletAcc.CreateDate;
                        walletSnapShot.UpdateDate         = walletAcc.UpdateDate;
                        walletSnapShot.CreateDateSnapshot = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour,
                                                                         DateTime.Now.Minute, DateTime.Now.Second);
                        walletSnapShot.Currency_Code = walletAcc.Currency_Code;
                        walletSnapShot.Checksum      = BuildCheckSum(walletSnapShot);
                        lstWalletSnapshot.Add(walletSnapShot);
                        S1 += walletSnapShot.ID + walletSnapShot.Account_ID + ConvertUtility.RoundToTwoDecimalPlaces(walletSnapShot.Balance) + ConvertUtility.RoundToTwoDecimalPlaces(walletSnapShot.Reward_Amount) + walletSnapShot.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + walletSnapShot.Currency_Code + walletSnapShot.Checksum;
                    }
                    var S1Hash = SecurityLogic.GetSha1Hash(S1);
                    foreach (Wallet_Snapshot Wallet_Snapshot in lstWalletSnapshot)
                    {
                        Wallet_Snapshot.Snapshot = S1Hash;
                    }

                    WalletTransactionUnitOfWork.DoInsertMany(lstWalletSnapshot).EndTransaction();
                }
                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }