public Thread_Comment Thread_AddComment(Thread_Comment comment) { Comment t = new Comment(); t = comment.Comment; if (t.commentID == null) { t.commentID = Guid.NewGuid().ToString(); } var filter = Builders <Thread> .Filter.Eq(x => x.threadID, comment.threadID); var update = Builders <Thread> .Update.AddToSet(x => x.Comments, t); var status = _threads.UpdateOne(filter, update); if (status == null) { return(null); } return(comment); //------------------------------------------------------------------------------ // // Add notification to all the subscribers and members that initiate this method // //------------------------------------------------------------------------------ }
public ActionResult <Thread> AddComment([FromBody] Thread_Comment comment) { Thread_Comment thread = new Thread_Comment(); thread = _ThreadService.Thread_AddComment(comment); if (thread == null) { return(BadRequest()); } return(Ok(thread)); }
public ActionResult Save() { foreach (string name in Request.Form.AllKeys) { try { int threadId = Convert.ToInt32(name); Thread t = _context.Threads.Single(m => m.Id == threadId); Comment c = new Comment(); if (Request[name] == "") { return(Redirect(Request.UrlReferrer.ToString())); } c.Description = Request[name]; c.UserId = User.Identity.GetUserName(); c.Date = DateTime.Now; c.ReplyTo = null; if (User.IsInRole(RoleName.Pvc) || User.IsInRole(RoleName.PvcChairman)) { c.Type = "PVC"; } else if (User.IsInRole(RoleName.Apqru)) { c.Type = "APQRU"; } else if (User.IsInRole(RoleName.ER)) { c.Type = "ER"; } else { c.Type = "UM"; } _context.Comments.Add(c); Thread_Comment tc = new Thread_Comment(); tc.Thread = t; tc.Comment = c; _context.Thread_Comment.Add(tc); _context.SaveChanges(); } catch (Exception e) { } } return(Redirect(Request.UrlReferrer.ToString())); }