Ejemplo n.º 1
0
    public static void Add(ProfitSource source, Pool targetPool, decimal percent)
    {
        var adminRule = GetAdministratorProfitRule(source);

        if (targetPool.Name != "Administrator Profit")
        {
            decimal difference = 0;

            ProfitPoolDistribution newRule = null;

            var where = TableHelper.MakeDictionary(Columns.ProfitSource, (int)source);
            where.Add(Columns.Pool, targetPool.Id);
            var whereRule = TableHelper.SelectRows <ProfitPoolDistribution>(where);

            if (whereRule.Count > 0)
            {
                newRule    = whereRule[0];
                difference = newRule.ProfitPoolPercent - percent;
            }
            else
            {
                newRule    = new ProfitPoolDistribution();
                difference = -percent;
            }

            newRule.ProfitPoolPercent = percent;
            newRule.ProfitSource      = source;
            newRule.Pool = targetPool.Id;
            newRule.Save();

            adminRule.ProfitPoolPercent += difference;
            adminRule.Save();
        }
    }
Ejemplo n.º 2
0
 public static void AddProfit(ProfitSource source, Money amount, ProfitPoolDistribution targetPool)
 {
     if (targetPool.Pool == PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn))
     {
         //Daily pool
         DailyPoolManager.AddToPool(targetPool.Pool, DateTime.Now, amount);
         AdPackProfitDistributionHistory.Add(amount);
     }
     else
     {
         //Global pool
         GlobalPoolManager.AddToPool(targetPool.Pool, amount);
     }
 }
Ejemplo n.º 3
0
    public static ProfitPoolDistribution GetAdministratorProfitRule(ProfitSource source)
    {
        var query = string.Format("SELECT TOP 1 * FROM ProfitPoolDistribution WHERE Pool = {0} AND ProfitSource = {1}",
                                  PoolsHelper.GetBuiltInProfitPoolId(Pools.AdministratorProfit), (int)source);

        var adminRule = TableHelper.GetListFromRawQuery <ProfitPoolDistribution>(query).SingleOrDefault();

        if (adminRule == null)
        {
            adminRule = new ProfitPoolDistribution()
            {
                ProfitPoolPercent = 100,
                ProfitSource      = source,
                Pool = PoolsHelper.GetBuiltInProfitPoolId(Pools.AdministratorProfit)
            };
            adminRule.Save();
        }
        return(adminRule);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Distributes the money from the Profit Source properly
    /// </summary>
    /// <param name="source"></param>
    /// <param name="amount"></param>
    public static bool AddProfit(ProfitSource source, Money amount)
    {
        if (amount != Money.Zero)
        {
            var where = TableHelper.MakeDictionary(ProfitPoolDistribution.Columns.ProfitSource, (int)source);
            var targetPools = TableHelper.SelectRows <ProfitPoolDistribution>(where);

            Money distributed = new Money(0);

            for (int i = 0; i < targetPools.Count; i++)
            {
                var   poolRule     = targetPools[i];
                Money toDistribute = new Money(0);

                //Last pool rule
                if (i == (targetPools.Count - 1))
                {
                    toDistribute = (amount - distributed);
                }
                else
                {
                    toDistribute = Money.MultiplyPercent(amount, poolRule.ProfitPoolPercent);
                    distributed += toDistribute;
                }

                if (poolRule.Pool == PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn))
                {
                    //Daily pool
                    DailyPoolManager.AddToPool(poolRule.Pool, AppSettings.ServerTime, toDistribute);
                    AdPackProfitDistributionHistory.Add(toDistribute);
                }
                else
                {
                    //Global pool
                    GlobalPoolManager.AddToPool(poolRule.Pool, toDistribute);
                }
            }
            return(distributed != Money.Zero);
        }
        return(false);
    }
Ejemplo n.º 5
0
 public static bool IsActive(ProfitSource source)
 {
     return(GetActiveProfitSources().Contains(source));
 }
Ejemplo n.º 6
0
 public static void SubtractProfit(ProfitSource source, Money amount)
 {
     AddProfit(source, amount.Negatify());
 }