Exemple #1
0
        /// <summary>
        /// 用户评论
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int PingLunTiTiao(Mldel.Contents.CommentModel model)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (qds105749277_dbEntities db = new qds105749277_dbEntities())
                    {
                        var sql1    = db.Comment.Where(c => c.ContentId == model.ContentId).ToList();
                        int louceng = 1;
                        if (sql1.Count > 0)
                        {
                            if (sql1.Count == 1)
                            {
                                louceng++;
                            }
                            else if (sql1.Count == 2)
                            {
                                louceng += 2;
                            }
                            else if (sql1.Count == 3)
                            {
                                louceng += 3;
                            }
                            else
                            {
                                louceng = (int)sql1[sql1.Count - 1].LouCeng + louceng;
                            }
                        }
                        Comment cm = new Comment()
                        {
                            Text      = model.Text,
                            ContentId = model.ContentId,
                            Time      = model.Time,
                            UserId    = model.UserId,
                            ZhiChi    = model.ZhiChi,
                            FanDui    = model.FanDui,
                            LouCeng   = louceng
                        };
                        //文章表的评论字段加一
                        var sql = db.Content.Where(c => c.Id == model.ContentId).FirstOrDefault();
                        if (sql != null)
                        {
                            sql.CommentNum += 1;
                        }

                        db.Comment.Add(cm);
                        int res = db.SaveChanges();
                        scope.Complete();
                        return(res);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
 /// <summary>
 /// 用户评论
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int PingLunTiTiao(Mldel.Contents.CommentModel model)
 {
     try
     {
         ContentDAL dal = new ContentDAL();
         return(dal.PingLunTiTiao(model));
     }
     catch (Exception)
     {
         throw;
     }
 }