Пример #1
0
        public static void CheckAndUpdateStatistics(StatisticsType Type)
        {
            Statistics Stat;

            switch (Type)
            {
            case StatisticsType.TotalMembersCount:
                Stat = new Statistics(Type);
                var where1 = new Dictionary <string, object>();

                where1.Add("AccountStatusInt", (int)MemberStatus.Active);
                int totalmember = TableHelper.CountOf <Member>(where1);

                where1.Add(Member.Columns.MembershipName, Memberships.Membership.Standard.Name);
                int upgradedmember = TableHelper.CountOf <Member>(where1);
                upgradedmember = totalmember - upgradedmember;

                //Now update
                var list1 = TableHelper.GetIntListFromString(Stat.Data1);
                list1[0]   = totalmember;
                Stat.Data1 = TableHelper.GetStringFromIntList(list1);

                var list2 = TableHelper.GetIntListFromString(Stat.Data2);
                list2[0]   = upgradedmember;
                Stat.Data2 = TableHelper.GetStringFromIntList(list2);

                Stat.Save();
                break;

            case StatisticsType.PointsInSystem:
                Stat = new Statistics(Type);

                //Now update
                var list888 = TableHelper.GetIntListFromString(Stat.Data1);
                list888[0] = AppSettings.Points.TotalInSystem;
                Stat.Data1 = TableHelper.GetStringFromIntList(list888);

                Stat.Save();
                break;

            case StatisticsType.PointsGenerated:
                Stat = new Statistics(Type);

                //Now update
                var list999        = TableHelper.GetIntListFromString(Stat.Data1);
                int totalNow       = AppSettings.Points.TotalGenerated;
                int totalYesterday = AppSettings.Points.TotalGeneratedUpToYesterday;
                int totalToday     = totalNow - totalYesterday;

                list999[0] = totalToday;
                Stat.Data1 = TableHelper.GetStringFromIntList(list999);

                Stat.Save();
                break;

            case StatisticsType.AvailableReferrals:
                Stat = new Statistics(Type);
                //Now update
                var list3 = TableHelper.GetIntListFromString(Stat.Data1);
                list3[0]   = RentReferralsSystem.GetAvailableNormalReferralsCount();
                Stat.Data1 = TableHelper.GetStringFromIntList(list3);

                Stat.Save();
                break;

            case StatisticsType.NormalRentedReferrals:
                Stat = new Statistics(Type);
                //Now update
                var list4 = TableHelper.GetIntListFromString(Stat.Data1);
                list4[0]   = RentReferralsSystem.GetRentedNormalReferralsCount();
                Stat.Data1 = TableHelper.GetStringFromIntList(list4);

                Stat.Save();
                break;

            case StatisticsType.BotRentedReferrals:
                Stat = new Statistics(Type);
                //Now update
                var list5 = TableHelper.GetIntListFromString(Stat.Data1);
                list5[0]   = RentReferralsSystem.GetRentedBotReferralsCount();
                Stat.Data1 = TableHelper.GetStringFromIntList(list5);

                Stat.Save();
                break;

            case StatisticsType.MoneyDistributedPerAdPack:
                Stat = new Statistics(Type);
                //Now update
                //TO DO: review
                var        list6 = TableHelper.GetMoneyListFromString(Stat.Data1);
                AdPackType type  = AdPackType.Standard;
                list6[0]   = new Money(type.Price.ToDecimal() * (type.FixedDistributionValuePercent / (Decimal)100));
                Stat.Data1 = TableHelper.GetStringFromMoneyList(list6);

                Stat.Save();
                break;

            case StatisticsType.AvailableFunds:

                //Handle
                var list = PaymentAccountDetails.AllGateways;

                foreach (var account in list)
                {
                    var where = TableHelper.MakeDictionary("Type", (int)StatisticsType.AvailableFunds);
                    where.Add("Data1", StatisticsManager.GetPaymentAccountName(account));

                    var TempStatList = TableHelper.SelectRows <Statistics>(where);
                    if (TempStatList.Count > 0)
                    {
                        Statistics stat = TempStatList[0];
                        if (stat != null)
                        {
                            stat.SetData2(account.Account.Balance);
                            stat.Save();
                        }
                    }
                }

                //var where2 = TableHelper.MakeDictionary("Type", (int)StatisticsType.AvailableFunds);
                //where2.Add("Data1", AppSettings.Cryptocurrencies.APIProvider.ToString());

                //var tempStatList2 = TableHelper.SelectRows<Statistics>(where2);
                //if (tempStatList2.Count > 0)
                //{
                //    var stat = tempStatList2[0];
                //    if (stat != null)
                //    {
                //        stat.SetData2(BitcoinAPIFacotry.Get().GetAccountBalance());
                //        stat.Save();
                //    }
                //}

                break;
            }
        }