Esempio n. 1
0
        //From U-A
        //From AP
        //If you made any changes here, also change TryToCreditAllOffers() metod
        public static void AcceptEntryManually(OfferRegisterEntry entry, Member user)
        {
            CPAManager.AcceptEntry(entry, user);

            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(user, CreditType.CPAGPTOffer);

            Crediter.CreditManual(entry);

            entry.Offer.PerformStatusControlCheck();
        }
Esempio n. 2
0
        //From AP
        public static void ReverseEntry(OfferRegisterEntry Entry, Member User)
        {
            CPAManager.DenyEntry(Entry, User, Entry.Offer.Title);

            User.TotalCPACompleted -= 1;

            //Now return the money back
            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(User, CreditType.CPAGPTOffer);

            Crediter.ReverseManual(Entry);
        }
Esempio n. 3
0
        //From Postback
        public static Money DenyEntryFromPostback(OfferRegisterEntry entry, Money balance, CreditAs creditAs, int offerId,
                                                  string networkName, string offerTitle, bool requiresConversion)
        {
            Money  Calculated = new Money(0);
            Member User       = new Member(entry.Username);

            CPAManager.DenyEntry(entry, User, offerTitle);

            User.TotalCPACompleted -= 1;

            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(User.Name, CreditType.CPAGPTOffer);

            Calculated = Crediter.ReverseCreditFromPostback(balance, creditAs, networkName, offerId, offerTitle, requiresConversion);

            return(Calculated);
        }
Esempio n. 4
0
        //From Postback
        public static Money AcceptEntryFromPostback(OfferRegisterEntry entry, Money balance, CreditAs creditAs, int offerId,
                                                    string networkName, string offerTitle, bool requiresConversion, out bool isLocked)
        {
            Money  Calculated = new Money(0);
            Member User       = new Member(entry.Username);

            CPAManager.AcceptEntry(entry, User);
            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(User.Name, CreditType.CPAGPTOffer);

            Calculated = Crediter.CreditFromPostback(balance, creditAs, networkName, offerId, offerTitle, entry._OfferId, requiresConversion);

            //isLocked = Crediter.isLocked;
            isLocked = false; //TODO

            return(Calculated);
        }
Esempio n. 5
0
        public static void TryToCreditAllOffers()
        {
            //Get all nonLocked Entries
            var entriesQuery = string.Format(@"SELECT * FROM OfferRegisterEntries WHERE OfferStatus = {0} OR OfferStatus = {1} AND HasBeenLocked = 0",
                                             (int)OfferStatus.Pending, (int)OfferStatus.UnderReview);
            var entriesList = TableHelper.GetListFromRawQuery <OfferRegisterEntry>(entriesQuery).OrderBy(x => x.Username);

            Member user = null;

            //Creadit all Entries
            foreach (var entry in entriesList)
            {
                if (user == null || (user == null && user.Name != entry.Username))
                {
                    user = new Member(entry.Username);
                }

                CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(user, CreditType.CPAGPTOffer);
                Crediter.CreditManual(entry);
            }

            //Change status of credited offers
            var changeCPAOffersStatusQuery = string.Format(@"
                        WITH CTE AS 
                            (SELECT OfferId, COUNT(*) As CounfOfDone FROM OfferRegisterEntries WHERE OfferStatus IN ({0}, {1}, {2}) GROUP BY OfferId),
                        CTE2 AS
                            (SELECT OfferId, COUNT(*) As CounfOfCompleted FROM OfferRegisterEntries WHERE OfferStatus = {0} GROUP BY OfferId)
                        UPDATE CPAOffers 
                            SET [Status] = (SELECT CASE 
                                WHEN(Id IN (SELECT OfferId FROM CTE) AND CreditsBought > (SELECT CounfOfDone FROM CTE WHERE OfferId = Id) and [Status] = {4})
                                    THEN {3}
                                WHEN(Id IN (SELECT OfferId FROM CTE) AND CreditsBought <= (SELECT CounfOfDone FROM CTE WHERE OfferId = Id) and [Status] = {3})
                                    THEN {4}
                                WHEN(Id IN (SELECT OfferId FROM CTE) AND CreditsBought <= (SELECT CounfOfCompleted FROM CTE2 WHERE OfferId = Id) and [Status] != {5})
                                    THEN {5}
                                ELSE [Status]
                                END) ",
                                                           (int)OfferStatus.Completed, (int)OfferStatus.Pending, (int)OfferStatus.UnderReview,
                                                           (int)AdvertStatus.Active, (int)AdvertStatus.Stopped, (int)AdvertStatus.Finished);

            //Increase Users TotalCPACompleted
            var increaseUsersTotalCPACompletedQuery = string.Format(@"
                        WITH CTE AS 
                            (SELECT Username, COUNT(*) AS CountOf FROM OfferRegisterEntries WHERE OfferStatus = {0} OR OfferStatus = {1} GROUP BY username)
                        UPDATE Users 
                            SET TotalCPACompleted += (SELECT CountOf FROM CTE WHERE Username = Users.Username)
                            WHERE Username IN 
                                (SELECT Username from CTE)",
                                                                    (int)OfferStatus.Pending, (int)OfferStatus.UnderReview);

            //Update status of completed entries
            var updateEntriesQuery = string.Format(@"
                        UPDATE OfferRegisterEntries 
                            SET OfferStatus = {0}, CompletedDate = GETDATE() WHERE OfferStatus = {1} OR OfferStatus = {2} AND HasBeenLocked = 0",
                                                   (int)OfferStatus.Completed, (int)OfferStatus.Pending, (int)OfferStatus.UnderReview);

            //Executing Queries in the correct order
            TableHelper.ExecuteRawCommandNonQuery(changeCPAOffersStatusQuery);
            TableHelper.ExecuteRawCommandNonQuery(increaseUsersTotalCPACompletedQuery);
            TableHelper.ExecuteRawCommandNonQuery(updateEntriesQuery);
        }