public ActionResult StartSubject(int?id, string Content, string Title) //burda gelen id topictitle id si { //topic title la topic i ekleyip guncelleme yapıcam ForumTopicTitle TopicTitle = Db.ForumTopicTitles.Find(id); if (Content != null) { //burda konu ismini yazıyor ayrıca sorusunuda soruyor hem topic oluşturuyorum hemde comment oluşturuyorum ForumCommentTopic NewTopic = new ForumCommentTopic(); NewTopic.TopicTitle = Title; NewTopic.ForumComments = new List <ForumComment>(); NewTopic.ForumTopicTitle = Db.ForumTopicTitles.Find(TopicTitle.TitleId); Db.ForumCommentTopics.Add(NewTopic); Db.SaveChanges(); ForumComment NewComment = new ForumComment(); NewComment.Content = Content; int UserID = (int)Session["EnterID"]; NewComment.ByUser = Db.Users.Find(UserID); int CommentTitleID = Db.ForumCommentTopics.OrderByDescending(x => x.TopicId).Take(1).Select(x => x.TopicId).FirstOrDefault(); NewComment.CommentTopic = Db.ForumCommentTopics.Find(CommentTitleID); Db.ForumComments.Add(NewComment); Db.SaveChanges(); return(View()); } return(View()); }
public async Task <IActionResult> Edit(string id, [Bind("Body,AuthorId,PostId,ParentId,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] ForumComment forumComment) { if (id != forumComment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(forumComment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ForumCommentExists(forumComment.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Users, "Id", "Id", forumComment.AuthorId); ViewData["ParentId"] = new SelectList(_context.ForumComments, "Id", "Id", forumComment.ParentId); ViewData["PostId"] = new SelectList(_context.ForumPosts, "Id", "Id", forumComment.PostId); return(View(forumComment)); }
public void AddComment(string content, int postid, int userid, string username, int parentid) { if (string.IsNullOrEmpty(content)) { throw new UserException("评论内容为空!"); } ForumComment comment = new ForumComment(); comment.Content = content; comment.PostId = postid; comment.UserId = userid; comment.ParentId = parentid; comment.DelFlag = DelFlag.Normal; comment.DateLine = DateTime.Now; //好友圈的动态我们手动来添加 object obj = DbSession.CommentDal.AddComment(comment); //如果事务失败,返回的id是什么样的类型呢?todo:测试 int useroperationid = Convert.ToInt32(obj); if (null == obj || useroperationid < -1) { throw new UserException("添加评论失败"); } //这一段从新考究 //记录好友操作 if (Convert.ToInt32(DbSession.FriendDal.GetFriendCount(userid)) > 0) { //添加好友记录 DbSession.FriendOperationDal.AddFirendOperation(DbSession.FriendDal.GetFriendsId(userid).ToArray(), userid, useroperationid, DateTime.Now); } }
public List <ForumComment> ListForumComments(int forum) { List <ForumComment> comments = new List <ForumComment>(); string sql = @"SELECT F.*, U.NAME FROM FORUM_COMMENTS F INNER JOIN USERS U ON (F.AUTHOR = U.ID) WHERE FORUM = ?"; using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.Parameters.Add(@"ID", MySqlDbType.Int32).Value = forum; using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ForumComment forumComments = new ForumComment(); forumComments.Id = reader.GetInt32("ID"); forumComments.Forum = reader.GetInt32("FORUM"); forumComments.Text = reader.GetString("COMMENT_TEXT"); forumComments.Author = reader.GetInt32("AUTHOR"); forumComments.AuthorName = reader.GetString("NAME"); comments.Add(forumComments); } } } return(comments); }
public ActionResult AddComment(ForumComment newComment) { try { if (Session["studentId"] != null) { int studentId = (int)Session["studentId"]; int forumId = (int)Session["forumId"]; string queryAddComment = string.Format("CALL platforma.add_forum_comment_as_a_student({0}, {1}, \'{2}\')", forumId, studentId, newComment.Comment); int output = db.Database.ExecuteSqlCommand(queryAddComment); } else { int instructorId = (int)Session["instructorId"]; int forumId = (int)Session["forumId"]; string queryAddComment = string.Format("CALL platforma.add_forum_comment_as_an_instructor({0}, {1}, \'{2}\')", forumId, instructorId, newComment.Comment); int output = db.Database.ExecuteSqlCommand(queryAddComment); } string _redirect = "Details/" + (int)Session["forumId"]; return(RedirectToAction(_redirect)); } catch { return(View()); } }
public async Task <IActionResult> Edit(int id, [Bind("commentID,postID,userID,content,timestamp")] ForumComment forumComment) { if (id != forumComment.commentID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(forumComment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ForumCommentExists(forumComment.commentID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(forumComment)); }
public IList <ForumComment> GetComments(IList <int> ids) { List <ForumComment> list = new List <ForumComment>(); if (null == ids || ids.Count == 0) { return(list); //如果没有id的话,直接返回一个空的集合 } string sql = ids.Aggregate("select commentid,postid,content from forum_comment where commentid in(", (current, id) => current + (id + ",")); //去掉逗号,加上括号 sql = sql.Substring(0, sql.Length - 1) + ")"; DataSet dataSet = new DataSet(); SqlHelper.GetDataTable(sql, CommandType.Text, dataSet); foreach (DataRow row in dataSet.Tables[0].Rows) { ForumComment model = new ForumComment(); model.CommentId = Convert.ToInt32(row[0]); model.Content = row[2].ToString(); model.PostId = Convert.ToInt32(row[1]); list.Add(model); } return(list); }
public ActionResult DeleteConfirmed(int id) { ForumComment forumComment = db.ForumComments.Find(id); db.ForumComments.Remove(forumComment); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult <ForumComment> > PutComment(ForumComment comment) { comment.UpdatedDate = DateTime.Now; await _comment.Update(comment); return(NoContent()); }
/// <summary> /// Delete a comment /// </summary> /// <param name="comment">comment to be deleted</param> /// <returns>ask of completion</returns> public async Task Delete(int id) { ForumComment comment = await _context.ForumComments.FindAsync(id); if (comment != null) { _context.Entry(comment).State = EntityState.Deleted; await _context.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("commentID,postID,userID,content,timestamp")] ForumComment forumComment) { if (ModelState.IsValid) { _context.Add(forumComment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(forumComment)); }
public void CommentPost() { ForumComment comment = new ForumComment { ForumPostId = 1, ForumUserId = "1", Text = "NewComment", Date = DateTime.Now }; ViewResult result = Comment.Comments(comment) as ViewResult; Assert.IsNotNull(result); MockComments.Verify(i => i.Add(It.IsAny <ForumComment>()), Times.Once()); MockContext.Verify(i => i.SaveChanges(), Times.Once()); }
public void Include(ForumComment forumComment) { string sql = "INSERT INTO FORUM_COMMENTS (FORUM, COMMENT_TEXT, AUTHOR) VALUES (?, ?, ?)"; using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.Parameters.Add(@"FORUM", MySqlDbType.Int32).Value = forumComment.Forum; command.Parameters.Add(@"COMMENT_TEXT", MySqlDbType.String).Value = forumComment.Text; command.Parameters.Add(@"AUTHOR", MySqlDbType.Int32).Value = forumComment.Author; command.ExecuteNonQuery(); } }
public ActionResult Edit([Bind(Include = "CommentId,Content,UserId,CommentTopicId,Permission")] ForumComment forumComment) { if (ModelState.IsValid) { db.Entry(forumComment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.Users, "UserId", "NameSurname", forumComment.UserId); ViewBag.CommentTopicId = new SelectList(db.ForumCommentTopics, "TopicId", "TopicTitle", forumComment.CommentTopicId); return(View(forumComment)); }
public ActionResult Include(ForumComment forumComment) { try { repository.Include(forumComment); return(Ok(new { success = true })); } catch (MySqlException ex) { throw ex; } }
public async Task AddCommentAsync(string text, string postId, string userId) { var comment = new ForumComment { Text = text, ForumPostId = postId, UserId = userId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); }
private ForumComment MapComment(IDataReader reader) { //Maps a sql row to a forum comment model int index = 0; ForumComment fc = new ForumComment(); fc.Id = reader.GetSafeInt32(index++); fc.Text = reader.GetSafeString(index++); fc.CreatedDate = reader.GetSafeDateTime(index++); fc.ModifiedDate = reader.GetSafeDateTime(index++); fc.ModifiedBy = reader.GetSafeString(index++); return(fc); }
public virtual OperationResult ReleaseForumComment(ForumComment ForumCommentInfo) { try { PublicHelper.CheckArgument(ForumCommentInfo, "FileResourceInfo"); ForumCommentRepository.Insert(ForumCommentInfo); return(new OperationResult(OperationResultType.Success, "文件分享成功。", ForumCommentInfo)); } catch (Exception ex) { return(new OperationResult(OperationResultType.Error, ex.Message.ToString())); } }
public async Task NewComment(NewCommentDto dto) { var memberInfo = await _memberRepository.FirstOrDefaultAsync(t => t.Id == dto.MemberId); if (memberInfo == null) { throw new UserFriendlyException("请先登录账户!"); } var postInfo = await _forumPostRepository.FirstOrDefaultAsync(t => t.Id == dto.PostId); if (postInfo == null) { throw new UserFriendlyException("回复的帖子不存在!"); } if (dto.Content.Length < 5) { throw new UserFriendlyException("回复内容不能少于5个字"); } if (dto.Content.Length > 100) { throw new UserFriendlyException("回复内容不能超过100个字"); } ForumComment forumComment = new ForumComment(); forumComment.MemberId = dto.MemberId; forumComment.ForumPostId = postInfo.Id; forumComment.Content = dto.Content; forumComment.Floor = postInfo.CommentCount + 1; postInfo.LastCommentTime = DateTime.Now; postInfo.CommentCount++; var commentId = await _forumCommentRepository.InsertAndGetIdAsync(forumComment); if (dto.Images != null && dto.Images.Count > 0) { foreach (var image in dto.Images) { ForumImage forumImage = new ForumImage(); forumImage.Type = ForumImageType.Comment; forumImage.Image = image; forumImage.OwnerId = commentId; await _forumImageRepository.InsertAsync(forumImage); } } await _forumPostRepository.UpdateAsync(postInfo); }
public async Task CreateForumComment(int forumPostId, string userId, string content, int?parentId = null) { var comment = new ForumComment { Content = content, ParentId = parentId, ForumPostId = forumPostId, UserId = userId, }; await this.forumCommentsRepository.AddAsync(comment); await this.forumCommentsRepository.SaveChangesAsync(); }
public async Task Create(int postId, string userId, string content, int?parentId = null) { var comment = new ForumComment() { Content = content, ParentId = parentId, PostId = postId, AuthorId = userId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); }
public async Task <ActionResult> AddCommentLike(ulong id) { User user = await _userManager.GetUserAsync(User); ForumComment comment = _context.ForumComments.FirstOrDefault(c => c.CommentID == id); if (comment == null) { return(Json("Comment not found!")); } if (user != null) { if (_context.ForumCommentLikes.Any(l => l.UserID == user.Id && l.CommentID == id)) { // Cancel because there is already a like return(Json("Failure")); } else { string likeid = $"{id}-{user.Id}"; // Success ForumCommentLike like = new ForumCommentLike() { UserID = user.Id, LikeID = likeid, CommentID = id, GivenTo = comment.UserID }; _context.ForumCommentLikes.Add(like); await _context.SaveChangesAsync(); User author = await _userManager.FindByIdAsync(like.GivenTo); author.comment_likes += 1; await _userManager.UpdateAsync(author); return(Json("Success")); } } else { // There is no user (?) return(Json("Failure")); } }
public async Task <IActionResult> Create([Bind("Body,AuthorId,PostId,ParentId,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] ForumComment forumComment) { if (ModelState.IsValid) { _context.Add(forumComment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Users, "Id", "Id", forumComment.AuthorId); ViewData["ParentId"] = new SelectList(_context.ForumComments, "Id", "Id", forumComment.ParentId); ViewData["PostId"] = new SelectList(_context.ForumPosts, "Id", "Id", forumComment.PostId); return(View(forumComment)); }
public void SaveForumComment(int forumID, string comment) { int participantID = (int)Session["User"]; ForumComment fc = new ForumComment() { Comment = comment, ForumID = forumID, ParticipantID = participantID, PostedOn = DateTime.Now }; dBEntities.ForumComments.Add(fc); dBEntities.SaveChanges(); }
// GET: Panel/ForumComments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ForumComment forumComment = db.ForumComments.Find(id); if (forumComment == null) { return(HttpNotFound()); } return(View(forumComment)); }
public async Task <ActionResult <ForumComment> > PostComment(ForumComment comment) { string username = User.Identity.Name.ToString(); ApplicationUser user = await _userManager.FindByNameAsync(username); comment.CreatedDate = DateTime.Now; comment.UpdatedDate = DateTime.Now; comment.Username = user.UserName; comment.Avatar = user.Avatar; comment.Upvotes = 0; comment.Downvotes = 0; await _comment.Create(comment); return(CreatedAtAction("GetBehavioralQ", new { id = comment.Id }, comment)); }
// GET: Panel/ForumComments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ForumComment forumComment = db.ForumComments.Find(id); if (forumComment == null) { return(HttpNotFound()); } ViewBag.UserId = new SelectList(db.Users, "UserId", "NameSurname", forumComment.UserId); ViewBag.CommentTopicId = new SelectList(db.ForumCommentTopics, "TopicId", "TopicTitle", forumComment.CommentTopicId); return(View(forumComment)); }
public async Task <TViewModel> Create <TViewModel>(string body, string parentId, string postId, string authorId) { var comment = new ForumComment { Body = body, ParentId = parentId, PostId = postId, AuthorId = authorId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); return(AutoMapperConfig.MapperInstance.Map <TViewModel>(comment)); }
public async Task <IActionResult> EditComment(ulong commentid, string content) { if (content.Length > 1000) { return(Json($"Error: Comment length is over 1000")); } if (String.IsNullOrWhiteSpace(content)) { return(Json($"Error: Comment is empty")); } if (!ModelState.IsValid) { return(Json($"Error: Model state is not valid.")); } ForumComment comment = _context.ForumComments.FirstOrDefault(c => c.CommentID == commentid); if (comment == null) { return(Json($"Failed to find the comment {commentid}.")); } User user = await _userManager.GetUserAsync(User); if (user == null) { return(Json($"Failed to find user!")); } if (user.Id != comment.UserID) { return(Json($"This is not your comment!")); } comment.Content = content; await _context.SaveChangesAsync(); StatusMessage = $"Successfully added comment!"; return(Json("Success")); }
public object AddComment(ForumComment comment) { //返回的是用户操作号id if (null == comment) { throw new UserException("评论对象为空"); } string sql = "usp_addcomment"; SqlParameter[] spm = SqlHelper.GetSqpParameters( new string[] { "@content", "postid", "@userid", "@parentid", "@delflag", "@dateline" }, new object[] { comment.Content, comment.PostId, comment.UserId, comment.ParentId, comment.DelFlag, comment.DateLine }, new SqlDbType[] { SqlDbType.NVarChar, SqlDbType.Int, SqlDbType.Int, SqlDbType.Int, SqlDbType.Int, SqlDbType.DateTime }); return(SqlHelper.ExecuteScalar(sql, CommandType.Text, spm)); }