public async Task <IActionResult> Delete(int id)
        {
            var command = new DeleteNotification(id);
            var result  = await _mediatr.Send(command);

            return(result != null ? (ActionResult)Ok(new { Message = "success" }) : NotFound(new { Message = "not found" }));
        }
        /// <inheritdoc />
        public Task <Unit> Handle(DeleteRequest <T> request, CancellationToken cancellationToken, RequestHandlerDelegate <Unit> next)
        {
            if (request == default)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (next == default)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (!_options.UseScopedLogging)
            {
                return(Handle());
            }

            using (request.Scope)
            {
                return(Handle());
            }

            async Task <Unit> Handle()
            {
                var start = new DeleteNotification <T>(request.Expression, request.Logger);
                await _mediator.Publish(start, cancellationToken).ConfigureAwait(false);

                var response = await next().ConfigureAwait(false);

                var finish = new DeleteNotification(request.Logger);
                await _mediator.Publish(finish, cancellationToken).ConfigureAwait(false);

                return(response);
            }
        }
        public Task Handle(DeleteNotification <TId> notification, CancellationToken cancellationToken)
        {
            if (notification == default)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            _cache.Remove(notification.Key);
            return(_database.KeyDeleteAsync(notification.Key.ToString(), FireAndForget));
        }
        /// <summary>
        /// Sends a NotificationRequestDeleteNotification message to a customer.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="changeTime">The change time.</param>
        /// <returns>The message identifier.</returns>
        public long DeleteNotification(IMessageHeader request, string uri, long changeTime)
        {
            var header = CreateMessageHeader(Protocols.StoreNotification, MessageTypes.StoreNotification.DeleteNotification, request.MessageId);

            var notification = new DeleteNotification()
            {
                Uri        = uri,
                ChangeTime = changeTime
            };

            return(Session.SendMessage(header, notification));
        }
Beispiel #5
0
        public async Task <IActionResult> DeleteAsset(
            [SwaggerParameter("The Asset Id", Required = true), FromODataUri, NotDefault] Guid id,
            CancellationToken cancellationToken)
        {
            IActionResult result;

            if (_cache.TryGetValue(id, out _))
            {
                var request = new DeleteRequest <Asset>(nameof(MongoDB), x => x.Id == id, _logger);
                await _mediator.Send(request, cancellationToken).ConfigureAwait(false);

                var notification = new DeleteNotification <Guid>(id);
                await _mediator.Publish(notification, cancellationToken).ConfigureAwait(false);

                result = NoContent();
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }
 /// <summary>
 /// Handles the DeleteNotification message from a store.
 /// </summary>
 /// <param name="header">The message header.</param>
 /// <param name="notification">The DeleteNotification message.</param>
 protected virtual void HandleDeleteNotification(IMessageHeader header, DeleteNotification notification)
 {
     Notify(OnDeleteNotification, header, notification);
 }