Example #1
0
        public async Task HandleAsync(DeletePermissionCommand message, CancellationToken token = default(CancellationToken))
        {
            var permission = await this.GetPermissionAsync(message.PermissionId, token);

            permission.Delete();
            _permissions.Delete(permission);
            await _permissions.SaveChangesAsync();
        }
        public async Task <bool> Handle(DeletePermissionCommand message, CancellationToken cancellationToken)
        {
            var permission = await _repository.GetById(message.Id) ?? throw new NotFoundException();

            await _repository.Delete(message.Id);

            await _mediator.Publish(new PermissionDeletedEvent(permission.Id, permission.Name));

            return(true);
        }
        public async Task <IActionResult> Delete([FromRoute] Guid id)
        {
            var command = new DeletePermissionCommand()
            {
                Id = id
            };
            await _mediator.Send(command);

            return(Ok());
        }
 public async Task <IActionResult> DeleteMultiple([FromQuery] Guid[] ids)
 {
     foreach (var id in ids)
     {
         var command = new DeletePermissionCommand()
         {
             Id = id
         };
         await _mediator.Send(command);
     }
     return(Ok());
 }
        public async Task <ActionResult <bool> > Delete(DeletePermissionCommand deletePermissionCommand)
        {
            try
            {
                bool success = await this.mediator.Send(deletePermissionCommand);

                return(Ok(success));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex));
            }
        }
        public async Task <IActionResult> Delete(DeletePermissionCommand command)
        {
            try
            {
                await _mediator.Send(command);

                return(Ok());
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound());
            }
            catch (ArgumentException argumentException)
            {
                return(BadRequest(argumentException.Message));
            }
        }
Example #7
0
        public async Task <IActionResult> Delete([FromQuery] DeletePermissionCommand cmd, int id)
        {
            try
            {
                if (id <= 0)
                {
                    ModelState.AddModelError("", "El permiso no puede ser en blanco");
                    return(BadRequest(ModelState));
                }

                cmd.Id = id;
                return(Ok(await _mediator.Send(cmd)));
            }
            catch (HttpRequestExceptionEx ex)
            {
                return(new NotFoundObjectResult(string.Format("Status code: {0} Message: {1}", ex.HttpCode, ex.Message)));
            }
        }
Example #8
0
        public async Task ShouldDeleteExisting()
        {
            // Arrange
            Permission entity     = Permission.Create(Guid.NewGuid(), "Name", "Code");
            var        repository = new Mock <IPermissionRepository>();

            repository.Setup(e =>
                             e.GetByIdAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(entity);
            DeletePermissionCommand cmd = new DeletePermissionCommand(entity.Id);

            PermissionCommandHandler actual = new PermissionCommandHandler(repository.Object);

            // Act
            await actual.HandleAsync(cmd);

            // Assert
            repository.Verify(e =>
                              e.Delete(It.Is <Permission>(a => a.Equals(entity))),
                              Times.Once
                              );
        }
 public async Task <IActionResult> DeleteMultiple(Guid[] ids)
 {
     try
     {
         foreach (var id in ids)
         {
             var command = new DeletePermissionCommand()
             {
                 Id = id
             };
             await _mediator.Send(command);
         }
         return(Ok());
     }
     catch (KeyNotFoundException ex)
     {
         return(NotFound());
     }
     catch (ArgumentException argumentException)
     {
         return(BadRequest(argumentException.Message));
     }
 }