public void DeletePost(int id) { DeletePostCommand.Execute(new { Id = id }); }
private dynamic DeletePost(DeletePostCommand deletePostCommand) { _commandInvokerFactory.Handle <DeletePostCommand, CommandResult>(deletePostCommand); string returnURL = Request.Headers.Referrer; return(Response.AsRedirect(returnURL)); }
public async Task ShouldRequireMinimunFields() { await RunAsDefaultUserAsync(); var command = new DeletePostCommand(); FluentActions.Invoking(() => SendAsync(command)) .Should().Throw <ValidationException>(); }
public async Task <IActionResult> DeletePost([FromRoute] int id) { var command = new DeletePostCommand() { Id = id }; return(Ok(await mediator.Send(command))); }
public void DeletePost(int id) { bool authorIsCaller = IsPostAuthorMatch <bool> .Execute(new { post.Author }); if (authorIsCaller) { DeletePostCommand.Execute(new { Id = id }); } }
public virtual async Task <IActionResult> Delete(int id) { return(await Runsafely(async() => { var deletePostCommand = new DeletePostCommand(id); var commandResult = await _mediator.Send(deletePostCommand); return commandResult ? Ok() : BadRequest(); })); }
public async Task <ActionResult> Delete(int id) { var deletepostCommand = new DeletePostCommand() { PostId = id }; await _mediator.Send(deletepostCommand); return(NoContent()); }
public async Task <ActionResult> Delete(int id, DeletePostCommand command) { if (id != command.Id) { return(BadRequest()); } await _mediator.Send(command); return(NoContent()); }
private void ConfirmDelete(int postID) { var page = (AdminPage)Page; if (page != null) { var command = new DeletePostCommand(Repository, postID, page.SearchEngine); command.Execute(); BindList(); } }
public ResultDto DeletePost(long id) { return(Result(() => { var command = new DeletePostCommand { PostId = id, }; CommandDispatcher.Send(command); })); }
public CommandsController( ApplicationDbContext context, HashtagFinder hashtagFinder, IHostingEnvironment appEnvironment, UserManager <ApplicationUser> userManager) { _userManager = userManager; _putLikeCommand = new PutLikeCommand(context); _followCommand = new FollowCommand(context); _createPostCommand = new CreatePostCommand(context, hashtagFinder, appEnvironment); _deletePostCommand = new DeletePostCommand(context, appEnvironment); }
public void ShouldNotCallHandleIfPostNotExist() { dbSetPost.Setup(x => x.FindAsync(id)).Returns(null); context.Setup(x => x.Posts).Returns(dbSetPost.Object); DeletePostCommandHandler deletePostCommandHandler = new DeletePostCommandHandler(context.Object, stringLocalizer.Object); DeletePostCommand deletePostCommand = new DeletePostCommand(id); Func <Task> act = async() => await deletePostCommandHandler.Handle(deletePostCommand, new CancellationToken()); act.Should().Throw <NotFoundException>(); }
public async Task ShouldCallHandle() { dbSetPost.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Post>(Task.FromResult(post))); context.Setup(x => x.Posts).Returns(dbSetPost.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1)); DeletePostCommandHandler deletePostCommandHandler = new DeletePostCommandHandler(context.Object, stringLocalizer.Object); DeletePostCommand deletePostCommand = new DeletePostCommand(id); var result = await deletePostCommandHandler.Handle(deletePostCommand, new CancellationToken()); result.Should().Be(Unit.Value); }
public async Task <IActionResult> DeleteAsync([FromRoute] Guid postId) { var command = new DeletePostCommand(postId); var deleted = await _mediator.Send(command); if (!deleted) { return(NotFound()); } return(NoContent()); }
public void ShouldNotCallHandleIfNotSavedChanges() { dbSetPost.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Post>(Task.FromResult(post))); context.Setup(x => x.Posts).Returns(dbSetPost.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0)); DeletePostCommandHandler deletePostCommandHandler = new DeletePostCommandHandler(context.Object, stringLocalizer.Object); DeletePostCommand deletePostCommand = new DeletePostCommand(id); Func <Task> act = async() => await deletePostCommandHandler.Handle(deletePostCommand, new CancellationToken()); act.Should().Throw <RestException>(); }
public void ShouldThrowNotFoundWhenPostIdIsIncorrect() { //arrange var deletepostCommand = new DeletePostCommand { Id = Guid.NewGuid() }; //act //assert FluentActions.Invoking(() => SendAsync(deletepostCommand)).Should().Throw <NotFoundException>(); }
public void Handler_GivenInvalidPostId_ThrowsException() { // Arrange var invalidPostId = 99; // Act var command = new DeletePostCommand { Id = invalidPostId }; var handler = new DeletePostCommand.DeletePostCommandHandler(Context); // Assert Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None)); }
/// <summary> /// Delete Post. /// </summary> /// <param name="id">Post identifier</param> /// <returns>Delete current post and redirect to page with posts.</returns> public async Task <IActionResult> Delete(int id, string returnUrl = default) { var postCommand = new DeletePostCommand { Id = id }; await _mediator.Send(postCommand); if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl)) { return(RedirectToAction("Index", "Posts")); } else { return(RedirectToAction(returnUrl)); } }
public async Task Handler_GivenValidPostId_ShouldRemovePost() { // Arrange var validPostId = 2; // Act var command = new DeletePostCommand { Id = validPostId }; var handler = new DeletePostCommand.DeletePostCommandHandler(Context); await handler.Handle(command, CancellationToken.None); // Assert var entity = Context.Posts.Find(command.Id); entity.ShouldBeNull(); }
public async Task <ResponseModel <bool> > Handle(DeletePostCommand request, CancellationToken cancellationToken) { var response = new ResponseModel <bool>() { Status = HttpStatusCode.InternalServerError, IsSuccessful = false, Result = false, Errors = default }; try { var post = await _postRepository.GetById(request.Id); if (post is null) { _logger.LogWarning($"{request.Id} is deleted"); return(_customExceptionBuilder.BuildEntityNotFoundException(response, request.Id, ErrorTypes.EntityNotFound)); } await _postRepository.DeleteAsync(post); response.Status = HttpStatusCode.OK; response.IsSuccessful = true; response.Result = true; return(response); } catch (Exception e) { _logger.LogCritical(e, e.StackTrace, "Method : DeletePostCommandHandler - Handle"); } response.Errors = new List <ErrorResponse>() { new ErrorResponse() { Reason = 500, Message = "An unexpected error occured" } }; return(response); }
public async Task <IActionResult> Delete(int id) { if (!ModelState.IsValid) { return(BadRequest(new ApiBadRequestResponse(ModelState))); } var command = new DeletePostCommand(id); var handler = _factory.Build(command); var response = await handler.Execute(); if (response.Success) { return(Ok(id)); } else { return(BadRequest(new ApiResponse(500))); } }
public ICommandHandler <DeletePostCommand, CommandResponse> Build(DeletePostCommand command) { return(new DeletePostCommandHandler(_serviceProvider.GetService <IPostsRepository>(), command)); }
public async Task <bool> Delete(long id) { DeletePostCommand command = new DeletePostCommand(id); return(await _bus.SendCommandAsync(command)); }
public async Task <ActionResult> Delete( [FromRoute] DeletePostCommand command) => await this.Send(command);
public async Task <ActionResult> Delete([FromBody] DeletePostCommand command) => Ok(await Handle(command));
public async Task Delete([FromBody] DeletePostCommand command) => await new DeletePostCommandHandler(persistence).Handle(command);
private dynamic DeletePost(DeletePostCommand deletePostCommand) { _commandInvokerFactory.Handle<DeletePostCommand, CommandResult>(deletePostCommand); string returnURL = Request.Headers.Referrer; return Response.AsRedirect(returnURL); }
public Task Delete( [FromRoute] DeletePostCommand command) => Mediator.Send(command);
public async Task Handle(DeletePostCommand cmd) { await _blogRepository.Delete(cmd.Id); }
public async Task <ActionResult <bool> > DeletePostAsync([FromBody] DeletePostCommand command) { var result = await _mediator.Send(command); return(Ok(ResponseWrapper.CreateOkResponseWrapper(result))); }
public async Task <IActionResult> Delete(DeletePostCommand command) { var result = await mediator.Send(command); return(RedirectToAction(nameof(Index))); }