Exemplo n.º 1
0
        public async virtual Task <IActionResult> DeleteAsync(int id)
        {
            if (!User.IsAuthorized(ResourceType))
            {
                return(Unauthorized());
            }

            var deleteResourceEvent = new DeleteResource <TResource>(id);
            var cancelDelete        = await _mediator.Send(deleteResourceEvent);

            if (cancelDelete)
            {
                return(Forbid());
            }

            var delete = await _repository.DeleteAsync(id, UserID);

            if (delete <= 0)
            {
                return(BadRequest());
            }

            _logger.LogResourceDeleted(ResourceType, id);

            var resourceDeletedEvent = new ResourceDeleted <TResource>(id);
            await _mediator.Publish(resourceDeletedEvent);

            return(NoContent());
        }
Exemplo n.º 2
0
        public void Can_roundtrip_ResourceDeleted_instance()
        {
            // Arrange
            var resourceEvent = new ResourceDeleted <MyResource>(
                "obliterated",
                new MyResource("test-1234", "My named resource"));

            // Act
            var asJson     = JsonSerializer.Serialize(resourceEvent, JsonSerializerOptions);
            var rehydrated = JsonSerializer.Deserialize <ResourceDeleted <MyResource> >(asJson, JsonSerializerOptions);

            // Assert
            rehydrated.Should().BeEquivalentTo(resourceEvent);
        }
Exemplo n.º 3
0
 private void OnResourceDeleted(Resource resource)
 {
     resource.Deleted -= OnResourceDeleted;
     resources.Remove(resource);
     ResourceDeleted?.Invoke(resource);
 }