public IHttpActionResult Remove(int Id) { RemoveComment Model = new RemoveComment { Id = Id, UserId = UserInfo.Id }; ApiResult <bool> rs = CommentDAL.Delete(Model); return(!rs.Succeeded ? Content(HttpStatusCode.BadRequest, rs) : (IHttpActionResult)Ok(rs)); }
public async Task <Comment> RemoveCommentAsync(RemoveComment command) { var comment = await _context.Comments.SingleOrDefaultAsync(x => x.Id == command.CommentId); comment.Status = CommentStatus.Deleted; await _context.SaveChangesAsync(); await _bus.Publish(new CommentAdded { RemarkId = comment.RemarkId, CommentId = comment.Id }); return(comment); }
public async Task <IActionResult> RemoveComment(Guid remarkId, Guid commentId) { var userId = HttpContext.GetUserId(); var command = new RemoveComment { RemarkId = remarkId, UserId = userId, CommentId = commentId }; var result = await _remarkService .RemoveCommentAsync(command) .OrFailAsync(); return(Ok(result)); }
public Task <Unit> Handle(RemoveComment request, CancellationToken cancellationToken) { var userId = _userService.UserId; var post = _postRepository.GetById(request.PostId); var aggregate = _personRepository.GetAggregateById(post.Person.PersonId); if (aggregate.GetComment(request.PostId, request.CommentId)?.Person.UserId != userId) { throw new Exception("Não é possivel deletar um comentario de outro usuario"); } aggregate.DeleteComment(request); _personRepository.Save(aggregate); return(Unit.Task); }
public async Task <IActionResult> RemoveComment(Guid id, Guid commentId) { var command = new RemoveComment { RemarkId = id, CommentId = commentId }; var comment = await _remarkService.RemoveCommentAsync(command); var dto = new CommentDto { Id = comment.Id, AuthorId = comment.AuthorId, Status = comment.Status.ToString(), Text = comment.Text }; return(Ok(dto)); }
public ApiResult <bool> Delete(RemoveComment Item) { ApiResult <bool> Rs = new ApiResult <bool>(); try { DbProvider.SetCommandText("sp_Comment_Remove", CommandType.StoredProcedure); DbProvider.AddParameter("UserId", Item.UserId, SqlDbType.Int); DbProvider.AddParameter("Id", Item.Id, SqlDbType.Int); DbProvider.AddParameter("ErrorCode", DBNull.Value, SqlDbType.NVarChar, 100, ParameterDirection.Output); DbProvider.AddParameter("ReturnMsg", DBNull.Value, SqlDbType.NVarChar, 4000, ParameterDirection.Output); DbProvider.ExecuteNonQuery(); // Kiểm tra kết quả trả về string errorCode = DbProvider.Command.Parameters["ErrorCode"].Value.ToString(); if (!errorCode.Equals(Constants.SUCCESS)) { Rs.Failed(new ErrorObject() { Code = DbProvider.Command.Parameters["ErrorCode"].Value.ToString(), Description = DbProvider.Command.Parameters["ReturnMsg"].Value.ToString() }); } } catch (Exception ex) { Rs.Failed(new ErrorObject { Code = Constants.ERR_EXCEPTION, Description = ex.ToString() }); } return(Rs); }
public void DeleteComment(RemoveComment cmd) { GetState().Posts.FirstOrDefault(x => x.PostId == cmd.PostId)?.Comments .Remove(GetComment(cmd.PostId, cmd.CommentId)); }
public async Task <IActionResult> RemoveComment([FromBody] RemoveComment command) => Json(await _userCommentService.RemoveComment(UserId, command.UserIdRated, command.EventId));
public async Task <Response <CommentDto> > RemoveCommentAsync(RemoveComment command) => await DeleteAsync <CommentDto>($"api/remarks/{command.RemarkId}/comments/{command.CommentId}");
public IActionResult RemoveComment(RemoveComment cmd) { _mediatorHandler.SendCommand(cmd); return(Ok()); }