public ActionResult add(postReply info) { try { //先判断有无回复的userId if (toolsHelpers.selectToolsController.selectUserInfo(u => u.userId == info.userId, u => u.userId).Length == 0) { return(Content("回复者不存在,请重新输入回复者Id")); } //判断有误此postId if (toolsHelpers.selectToolsController.selectPostInfo(u => u.postId == info.postId, u => u.postId).Length == 0) { return(Content("此论坛不存在!")); } info.replyTime = DateTime.Now; //判断插入是否成功 if (toolsHelpers.insertToolsController.insertPostReply(info) == true) { return(Content("增加评论成功!")); } return(Content("增加评论失败!")); } catch { return(Content("增加评论出错!")); } }
/// <summary> /// 向论坛回复表中插入信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public static Boolean insertPostReply(postReply info) { try { using (LazyfitnessEntities db = new LazyfitnessEntities()) { db.postReply.Add(info); db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// 查找论坛回复表中的数据 /// </summary> /// <typeparam name="TKey"></typeparam> /// <param name="whereLambda"></param> /// <param name="orderBy"></param> /// <returns></returns> public static postReply[] selectPostReply <TKey>(Expression <Func <postReply, bool> > whereLambda, Expression <Func <postReply, TKey> > orderBy) { try { using (LazyfitnessEntities db = new LazyfitnessEntities()) { DbQuery <postReply> dataObject = db.postReply.Where(whereLambda).OrderBy(orderBy) as DbQuery <postReply>; postReply[] infoList = dataObject.ToArray(); return(infoList); } } catch { postReply[] nullInfo = new postReply[0]; return(nullInfo); } }
public void forumReply(int quesId, string reply, int userId) { postReply prInfo = new postReply { postId = quesId, userId = userId, replyTime = DateTime.Now, replyContent = reply }; using (LazyfitnessEntities db = new LazyfitnessEntities()) { db.postReply.Add(prInfo); db.SaveChanges(); Response.Redirect(Url.Action("forumDetail", "Home", new { num = quesId })); } }