Esempio n. 1
0
        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));
        }
Esempio n. 3
0
 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));
        }
Esempio n. 5
0
        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();
        }
Esempio n. 7
0
        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()));
            }
        }
Esempio n. 8
0
 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());
 }
Esempio n. 9
0
        //[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"));
        }
Esempio n. 10
0
        public async Task <IActionResult> DeleteAuthor([FromBody] DeleteAuthorCommand command)
        {
            await _mediator.Send(command, HttpContext.RequestAborted);

            return(Ok());
        }
Esempio n. 11
0
 public Task DeleteAuthor(
     [FromRoute] DeleteAuthorCommand command)
 => Mediator.Send(command);