public async Task <bool> UpdateAsync(Comment comment) { try { comment.NullCheck(nameof(comment)); var target = await _context.CommentEntities.FindAsync(comment.Id); if (target is null) { return(false); } var entity = DbEntityConverter.ToCommentEntity(comment); target.Content = entity.Content; target.CreatedAt = entity.CreatedAt; target.PostId = entity.PostId; target.UserId = entity.UserId; target.ParentId = entity.ParentId; await _context.SaveChangesAsync(); } catch { return(false); } return(true); }
public async Task <int> CreateAsync(Comment comment) { try { comment.NullCheck(nameof(comment)); var entity = DbEntityConverter.ToCommentEntity(comment); await _context.CommentEntities.AddAsync(entity); await _context.SaveChangesAsync(); return(entity.Id); } catch { return(-1); } }