예제 #1
0
        /// <summary>
        /// 详情页
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Posts        posts         = db.Posts.Find(id);
            PostsComment postsComments = db.PostsComment.Find(id);

            if (posts == null)
            {
                return(HttpNotFound());
            }

            var postsComment = from m in db.PostsComment.Where(p => p.PID == id).OrderByDescending(p => p.PCTime) select m;
            var postsReply   = from m in db.PostsReply.OrderByDescending(r => r.PRTime) select m;
            var index        = new App.Models.PostsViewModel()
            {
                Posts         = posts,
                PostsComment  = postsComments,
                PostsComment1 = postsComment,
                PostsReply1   = postsReply,
            };

            return(View(index));
        }
예제 #2
0
        protected void btnSay_Click(object sender, EventArgs e)
        {
            string content = this.txtAre.Value.Trim();

            if (content.Length == 0)
            {
                Page.RegisterStartupScript("", "<script>alert('Please write your comments');location.href=location.href;</script>");
                return;
            }
            if (_PId.HasValue)
            {
                PostsComment entity = new PostsComment()
                {
                    UserID     = (Session["UserInfo"] as UserInfo).UserID,
                    PostsId    = _PId.Value,
                    Conent     = content,
                    CreateTime = DateTime.Now
                };
                if (new PostsCommentManager().AddPostsComment(entity))
                {
                    Page.RegisterStartupScript("", "<script>alert('The comment was added successfully');location.href=location.href;</script>");
                }
                else
                {
                    Page.RegisterStartupScript("", "<script>alert('The comment was added successfully');location.href=location.href;</script>");
                    return;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 添加表数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool AddPostsComment(PostsComment entity)
        {
            string sql = "insert into PostsComment(UserId,PostsId,Conent,CreateTime) values(@uid,@pid,@conent,@time)";

            SqlParameter[] pars = new SqlParameter[]
            {
                new SqlParameter("@uid", entity.UserID),
                new SqlParameter("@pid", entity.PostsId),
                new SqlParameter("@conent", entity.Conent),
                new SqlParameter("@time", entity.CreateTime)
            };
            return(DBHelper.ExecuteNonQuery(sql, CommandType.Text, pars) > 0);
        }
예제 #4
0
        public ActionResult Comment(PostsComment postsComment)
        {
            string Commenttextarea = Request["Commenttextarea"];
            int    pid             = Convert.ToInt32(Request["pid"]);
            int    UserID          = Convert.ToInt32(Session["UserID"].ToString());
            Users  users           = db.Users.Find(UserID);
            int    id = pid;

            if (ModelState.IsValid)
            {
                postsComment.PID       = pid;
                postsComment.UserID    = Convert.ToInt32(Session["UserID"].ToString());
                postsComment.PCContent = Commenttextarea;
                postsComment.PCTime    = System.DateTime.Now;
                db.PostsComment.Add(postsComment);
                db.SaveChanges();
            }

            return(RedirectToAction("Details", "Posts", new { id }));
        }
예제 #5
0
 /// <summary>
 /// 添加表数据
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public bool AddPostsComment(PostsComment entity)
 {
     return(ms.AddPostsComment(entity));
 }