Beispiel #1
0
        public int Against(string commentID, string userID, string ip)
        {
            IDbHelper db = IocFactory <FYJ.Data.IDbFactory> .Instance.GetDbInstance("Comment");

            string sql = string.Empty;

            if (!String.IsNullOrEmpty(userID))
            {
                sql = "select * from blog_tb_commentSupport where commentID=@commentID and userID=@UserID and isSupport=@isSupport";
                if (db.Exists(sql
                              , db.CreateParameter("@commentID", commentID)
                              , db.CreateParameter("@userID", userID)
                              , db.CreateParameter("@isSupport", false)
                              ))
                {
                    throw new CustomException("你已经反对过了");
                }
            }

            sql = "select * from blog_tb_commentSupport where commentID=@commentID and supportIP=@supportIP and isSupport=@isSupport";
            if (db.Exists(sql
                          , db.CreateParameter("@commentID", commentID)
                          , db.CreateParameter("@supportIP", ip)
                          , db.CreateParameter("@isSupport", false)
                          ))
            {
                throw new CustomException("你已经反对过了");
            }

            blog_tb_commentSupport support = new blog_tb_commentSupport {
                supportID = Guid.NewGuid().ToString("N"), supportIP = ip, commentID = commentID, supportDatetime = DateTime.Now, isSupport = false, UPDATE_DATE = DateTime.Now
            };

            FYJ.Data.Entity.EntityHelper <blog_tb_commentSupport> .Insert(support, "blog_tb_commentSupport", "supportID", true, db);

            sql = "update blog_tb_comment set againstCount=IFNULL(againstCount,0)+1 where commentID=@commentID";

            return(db.ExecuteSql(sql, db.CreateParameter("@commentID", commentID)));
        }
Beispiel #2
0
        public int Support(string commentID, string userID, string ip)
        {
            string sql = string.Empty;

            if (!String.IsNullOrEmpty(userID))
            {
                sql = "select * from blog_tb_commentSupport where commentID=@commentID and userID=@UserID and isSupport=@isSupport";
                if (DbInstance.Exists(sql
                                      , DbInstance.CreateParameter("@commentID", commentID)
                                      , DbInstance.CreateParameter("@userID", userID)
                                      , DbInstance.CreateParameter("@isSupport", true)
                                      ))
                {
                    throw new CustomException("你已经支持过了");
                }
            }

            sql = "select * from blog_tb_commentSupport where commentID=@commentID and supportIP=@supportIP and isSupport=@isSupport";
            if (DbInstance.Exists(sql
                                  , DbInstance.CreateParameter("@commentID", commentID)
                                  , DbInstance.CreateParameter("@supportIP", ip)
                                  , DbInstance.CreateParameter("@isSupport", true)
                                  ))
            {
                throw new CustomException("你已经支持过了");
            }

            blog_tb_commentSupport support = new blog_tb_commentSupport {
                supportID = Guid.NewGuid().ToString("N"), supportIP = ip, commentID = commentID, supportDatetime = DateTime.Now, isSupport = true, UPDATE_DATE = DateTime.Now
            };

            FYJ.Data.Entity.EntityHelper <blog_tb_commentSupport> .Insert(support, "blog_tb_commentSupport", "supportID", true, this.DbInstance);

            sql = "update blog_tb_comment set supportCount=supportCount+1 where commentID=@commentID";
            return(this.DbInstance.ExecuteSql(sql, this.DbInstance.CreateParameter("@commentID", commentID)));
        }