public JsonResult Comment(int topic, string comment) { if (topic == 0) { return(Json(new { status = HttpStatusCode.BadRequest })); } var cTopic = communityService.GetTopic(topic); if (cTopic == null) { return(Json(new { status = HttpStatusCode.NotFound })); } if (String.IsNullOrEmpty(comment)) { return(Json(new { status = HttpStatusCode.NoContent })); } ApplicationUser user = memberService.GetUser(User.Identity.Name); CommuityTopicComment commentTopic = new CommuityTopicComment { Content = comment, ComemmentTime = DateTime.Now, CommentUserId = user.Id, CommunityTopicID = topic }; communityService.CreateComment(commentTopic); communityService.SaveTopic(); var jsonData = new { status = HttpStatusCode.OK, data = new { Id = commentTopic.ID, Content = commentTopic.Content, Name = commentTopic.CommentUser.FullName, ComemmentTime = commentTopic.ComemmentTime.ToString() } }; return(Json(jsonData)); }
public JsonResult DeleteComment(int id) { CommuityTopicComment comment = this.communityService.GetComment(id); if (comment != null) { if (comment.CommentUser.UserName == User.Identity.Name) { communityService.DeleteComment(comment); communityService.SaveTopic(); } else { return(Json("")); } } return(Json(new { status = HttpStatusCode.OK })); }
public void DeleteComment(CommuityTopicComment comment) { this.context.CommuityTopicComments.Remove(comment); }
public void CreateComment(CommuityTopicComment comment) { this.context.CommuityTopicComments.Add(comment); }