public async Task <ActionResult> DeleteBook(int id) { var deleteAuthorCommand = new DeleteAuthorCommand() { Id = id }; await _mediator.Send(deleteAuthorCommand); return(NoContent()); }
public async Task <IActionResult> Delete([FromBody] DeleteAuthorCommand deleteAuthorCommand) { var result = await _mediator.Send(deleteAuthorCommand); if (!result.Success) { return(BadRequest(result.Message)); } return(Ok(result.Message)); }
public AuthorsViewModel() { authorsList = new ObservableCollection <AuthorModel> { //new AuthorModel { Id=1, FirstNameAuthor="Jan", LastNameAuthor="Kowalski"}, //new AuthorModel { Id = 2, FirstNameAuthor = "Ambrozja", LastNameAuthor = "Raduńska" } }; DataGrid_Loaded(); addAuthorCommand = new AddAuthorCommand(this); deleteAuthorCommand = new DeleteAuthorCommand(this); }
public void Handler_GivenInvalidAuthorId_ThrowsException() { // Arrange var invalidAuthorId = 99; // Act var command = new DeleteAuthorCommand { Id = invalidAuthorId }; var handler = new DeleteAuthorCommand.DeleteAuthorCommandHandler(Context); // Assert Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None)); }
public async Task DeleteAuthorTestNormal() { var authorToDelete = _authorFaker.Generate(); _dbContext.GetAuthor(authorToDelete.Id).Returns(authorToDelete); var deleteAuthorCommandHandler = new DeleteAuthorCommandHandler(_dbContext); var deleteAuthorCommand = new DeleteAuthorCommand { Id = authorToDelete.Id }; var deleted = await deleteAuthorCommandHandler.Handle(deleteAuthorCommand, CancellationToken.None); deleted.Should().Be(true); }
public async Task Handler_GivenValidAuthorId_ShouldRemoveAuthor() { // Arrange var validAuthorId = 3; // Act var command = new DeleteAuthorCommand { Id = validAuthorId }; var handler = new DeleteAuthorCommand.DeleteAuthorCommandHandler(Context); await handler.Handle(command, CancellationToken.None); // Assert var entity = Context.Authors.Find(command.Id); entity.ShouldBeNull(); }
public async Task <IActionResult> Delete([FromRoute] Guid authorId) { var deleteAuthorCommand = new DeleteAuthorCommand { Id = authorId }; try { var deleted = await _mediator.Send(deleteAuthorCommand); if (deleted) { return(NoContent()); } return(NotFound()); } catch (Exception e) { return(BadRequest(e.ToString())); } }
public IActionResult DeleteAuthor(Guid id) { if (ModelState.IsValid) { DeleteAuthorCommand deleteAuthorCommand = new DeleteAuthorCommand(id); try { var result = _messages.Dispatch(deleteAuthorCommand); return(Ok(result)); } catch (DomainException ex) { _logger.LogError(ex.Message); return(Error(ex.Message)); } catch (Exception ex) { _logger.LogCritical(ex.Message); return(StatusCode(500)); } } return(BadRequest()); }
//[HttpPost] public async Task <IActionResult> Delete(int id) { var authorQuery = new GetAuthorQuery { Id = id }; var authorDTO = await _mediator.Send(authorQuery); if (authorDTO == null) { return(NotFound()); } var result = await _identityService.DeleteUserAsync(authorDTO.UserId); if (result.Succeeded) { var authorCommand = new DeleteAuthorCommand { Id = id }; await _mediator.Send(authorCommand); } return(RedirectToAction("Index", "Authors")); }
public async Task <IActionResult> DeleteAuthor([FromBody] DeleteAuthorCommand command) { await _mediator.Send(command, HttpContext.RequestAborted); return(Ok()); }
public Task DeleteAuthor( [FromRoute] DeleteAuthorCommand command) => Mediator.Send(command);