public async Task <ActionResult <Comment> > PostComment(int id, Comment comment) { comment.CreateDate = DateTime.Now; _context.Comments.Add(comment); try { await _context.SaveChangesAsync(); var infromComment = new InformComment(); infromComment.JustSee = false; infromComment.IdUserReceiced = id; infromComment.CommentId = comment.Id; _context.InformComments.Add(infromComment); await _context.SaveChangesAsync(); await _hubContext.Clients.All.BroadcastMessage(); } catch (DbUpdateException) { if (CommentExists(comment.Id)) { return(Conflict()); } else { throw; } } List <Comment> listcomments = new List <Comment>(); var commentNew = await _context.Comments.Include(a => a.User).Where(a => a.Id == comment.Id) .Select(c => new Comment { Id = c.Id, CommentUser = c.CommentUser, CreateDate = c.CreateDate, User = c.User, PostId = c.PostId, ParentCommentId = c.ParentCommentId, ChildComments = listcomments }) .FirstOrDefaultAsync(); //var commentNew = await _context.Comments.Include(a => a.User).Where(a => a.Id == comment.Id).FirstOrDefaultAsync(); return(commentNew); }
public async Task <ActionResult <InformComment> > PutCommentNotifyByOneUser(int id, InformComment inform) { if (id != inform.Id) { return(BadRequest()); } _context.Entry(inform).State = EntityState.Modified; try { await _context.SaveChangesAsync(); await _hubContext.Clients.All.BroadcastMessage(); } catch (DbUpdateConcurrencyException) { if (!InformCommentsExists(id)) { return(NotFound()); } else { throw; } } var informNew = _context.InformComments.Where(a => a.Id == id).FirstOrDefault(); return(informNew); }