Пример #1
0
        private static UndercoverResult GetByVariableTCost(DirectContainer container, string affID)
        {
            UndercoverResult result = null;
            var    banana           = new BananaclicksUndercoverManager();
            double tcost            = container.GetDouble("tcost").Value;

            //
            // Affiliate price from bananaclicks

            double?affPrice = banana.GetAffiliateProfit(affID);

            if (!affPrice.HasValue)
            {
                Log(string.Empty, "[FATAL]:: THERE IS NO affPrice for affiliate=" + affID);
                return(null);
            }
            affPrice = DollarConversion.Convert(affPrice.Value);

            //
            // Current transactions from database

            int?currentTransactions = banana.GetAffiliateCurrentTransactions(affID);

            if (!currentTransactions.HasValue)
            {
                Log(string.Empty, "[FATAL]:: THERE IS NO currentTransactions for affiliate=" + affID);
                return(null);
            }
            else
            {
                currentTransactions += 1;
            }


            //
            // Current price [bananaclicks price] / [conversions from database]

            double current_price = 0.0;

            if (affPrice.Value == 0.0 || affPrice.Value > 0 && currentTransactions.Value == 1)
            {
                current_price = 0.0;
            }
            else
            {
                current_price = affPrice.Value / (currentTransactions.Value * 1.0);
            }

            string logString = string.Format("affID={0}, tcost={1}, affiliate_profit={2}, current_price={3}, current_transactions={4} ", affID, tcost, Math.Round(affPrice.Value, 2), Math.Round(current_price, 2), currentTransactions.Value);

            //
            // Logic for undercover

            if (current_price == 0 || current_price <= tcost)
            {
                logString += " (REPORT)";
                result     = UndercoverResult.SendToBananaclicks();
            }
            else
            {
                logString += " THIS WILL NOT BE REPORTED";
                result     = new UndercoverResult()
                {
                    DontSendConversionToBananaclicks = true
                };
            }

            Log(string.Empty, logString);
            return(result);
        }