예제 #1
0
 static NewsHitService()
 {
     if (instance == null)
     {
         lock (lockObj)
         {
             instance = new NewsHitService();
         }
     }
 }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddNewsHit(string id)
        {
            NewsHitService nhs = NewsHitService.GetInstance();

            try
            {
                using (DbTrans t = BeginTransaction())
                {
                    cmsNews n = GetModel(id);
                    if (n != null)
                    {
                        n.Attach();

                        n.Hits++;

                        UpdateModel(n);
                    }

                    nhs.SetTransaction(t);
                    DateTime   now = DateTime.Now;
                    cmsNewsHit nh  = nhs.GetModelWithWhere(cmsNewsHit._.NewsId == id && cmsNewsHit._.HitDate == now.ToString("yyyy-MM-dd"));
                    if (nh == null)
                    {
                        nh         = new cmsNewsHit();
                        nh.NewsId  = id;
                        nh.Hits    = 1;
                        nh.HitDate = DateTime.Parse(now.ToString("yyyy-MM-dd"));

                        nhs.AddModel(nh);
                    }
                    else
                    {
                        nh.Attach();
                        nh.Hits = nh.Hits + 1;

                        nhs.UpdateModel(nh);
                    }

                    t.Commit();

                    return(1);
                }
            }
            catch
            {
                return(0);
            }
        }