Example #1
0
        public override void BeforeSave()
        {
            base.BeforeSave();

            if (Id>0)
            {
                var delta = this.ViewCount - (int)this.GetOriginalValues()["ViewCount"];
                if (delta > 0)
                {
                    var pal = Provider.Database.Read<PostAdLog>("PostId={0} AND InsertDate={1}", this.PostId, DateTime.Now.Date);
                    if (pal == null)
                        pal = new PostAdLog { PostId = this.PostId, InsertDate = DateTime.Now.Date };
                    pal.ViewCount += delta;
                    pal.Save();

                    // 1 CPM = 1 TL hesap ediyoruz
                    // Ödenen para kuruş cinsinden olduğuna göre 1 CPM = 1000 views = 100 kuruş
                    // Bu durumda 10 views = 1 kuruş. Yani kuruş olarak ödenen paranın 10 katı view yapılacak
                    if(this.PaymentTransaction.Amount*10 <= this.ViewCount)
                        this.AdStatus = AdStatus.Completed;
                }
            }

            if (Id==0)
            {
                HttpContext.Current.Cache.Remove("post_ads");
                this.PaymentTransactionId = Provider.Database.GetInt("select max(Id) from PaymentTransaction where InsertUserId = " + Provider.User.Id);
            }
        }
Example #2
0
        public override void BeforeSave()
        {
            base.BeforeSave();

            if (Id > 0)
            {
                var delta = this.ViewCount - (int)this.GetOriginalValues()["ViewCount"];
                if (delta > 0)
                {
                    var pal = Provider.Database.Read <PostAdLog>("PostId={0} AND InsertDate={1}", this.PostId, DateTime.Now.Date);
                    if (pal == null)
                    {
                        pal = new PostAdLog {
                            PostId = this.PostId, InsertDate = DateTime.Now.Date
                        }
                    }
                    ;
                    pal.ViewCount += delta;
                    pal.Save();

                    // 1 CPM = 1 TL hesap ediyoruz
                    // Ödenen para kuruş cinsinden olduğuna göre 1 CPM = 1000 views = 100 kuruş
                    // Bu durumda 10 views = 1 kuruş. Yani kuruş olarak ödenen paranın 10 katı view yapılacak
                    if (this.PaymentTransaction.Amount * 10 <= this.ViewCount)
                    {
                        this.AdStatus = AdStatus.Completed;
                    }
                }
            }

            if (Id == 0)
            {
                HttpContext.Current.Cache.Remove("post_ads");
                this.PaymentTransactionId = Provider.Database.GetInt("select max(Id) from PaymentTransaction where InsertUserId = " + Provider.User.Id);
            }
        }
    }