Ejemplo n.º 1
0
 public void Count(string activityId)
 {
     lock (asyncLock)
     {
         try
         {
             if (!string.IsNullOrWhiteSpace(activityId))
             {
                 Expression <Func <TRP_OpenCount, bool> > exp = a => a.ActivityId == activityId;
                 var iquerable = idal.FindBy(exp);
                 var list      = iquerable.ToList();
                 if (list.Count == 0)
                 {
                     TRP_OpenCount model = new TRP_OpenCount();
                     model.ActivityId = activityId;
                     model.Count      = 1;
                     idal.Add(model);
                     idal.Save();
                 }
                 else
                 {
                     TRP_OpenCount model = list.FirstOrDefault();
                     model.Count = model.Count + 1;
                     idal.Edit(model);
                     idal.Save();
                 }
             }
         }
         catch (Exception ex)
         {
             Logger.Error(string.Format("红包打开计数异常,异常信息:{0}", ex.ToString()));
         }
     }
 }
        /// <summary>
        /// 计数
        /// </summary>
        /// <param name="activityId"></param>
        public bool QrOpenCount(string activityId, ref string msg)
        {
            lock (asyncLock)
            {
                bool success = false;
                try
                {
                    DynamicParameters param = new DynamicParameters();
                    if (!string.IsNullOrWhiteSpace(activityId))
                    {
                        param.Add("ActivityId", activityId);
                        string        querysql = @"SELECT * FROM TRP_OpenCount WHERE ActivityId=@ActivityId";
                        TRP_OpenCount model    = idal.FindOne <TRP_OpenCount>(querysql, param, false);
                        if (model == null)
                        {
                            TRP_OpenCount entity = new TRP_OpenCount();
                            entity.ActivityId = activityId;
                            entity.Count      = 1;
                            string insertsql = @"INSERT INTO TRP_OpenCount
                                          (
                                              [Count]
                                              ,[ActivityId]
                                           )
                                        VALUES
                                           (
                                             @Count
                                             ,@ActivityId
                                            )            ";
                            idal.CreateEntity <TRP_OpenCount>(insertsql, entity);
                            success = true;
                        }
                        else
                        {
                            model.Count = model.Count + 1;
                            param.Add("Count", model.Count);
                            param.Add("ActivityId", activityId);
                            string updatesql = @"UPDATE TRP_OpenCount SET  Count=@Count WHERE ActivityId=@ActivityId";
                            idal.ExcuteNonQuery <TRP_OpenCount>(updatesql, param, false);
                            success = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    msg = "SERVER_ERROR";
                    Logger.Error(string.Format("点击计数异常,异常信息:{0}", ex.ToString()));
                }

                return(success);
            }
        }