Exemplo n.º 1
0
        public void Delete(Guid id)
        {
            var command = new DeleteTodoItem()
            {
                Id = id,
            };
            var service = new DeleteTodoItemService(context);

            service.Handle(command);
        }
        public async Task <ActionResult> DeleteConfirmed(
            Guid id,
            CancellationToken cancellationToken)
        {
            var command  = new DeleteTodoItem(id);
            var envelope = new Envelope(command);
            await MessageBus.Send(envelope, cancellationToken);

            return(RedirectToAction("Index"));
        }
        public void Handle(DeleteTodoItem command)
        {
            var id = command.Id;

            var item = (from i in context.TodoItems
                        where i.Id == id
                        select i).First();

            context.TodoItems.Remove(item);
            context.SaveChanges();
        }
Exemplo n.º 4
0
        public async Task Handle(
            Envelope <DeleteTodoItem> envelope,
            CancellationToken cancellationToken)
        {
            DeleteTodoItem command   = envelope.Message;
            Guid           messageId = envelope.MessageId;

            TodoItem todoItem = await
                                _repository.Find(command.TodoItemId, cancellationToken);

            if (todoItem == null)
            {
                throw new InvalidOperationException(
                          $"Cannot find todo item with id '{command.TodoItemId}'.");
            }

            todoItem.Delete();

            await _repository.Save(todoItem, messageId, cancellationToken);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Delete(DeleteTodoItem request)
        {
            await mediator.Send(request);

            return(Ok());
        }