예제 #1
0
        public override async Task <AddToDoCommand> HandleAsync(AddToDoCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new ToDoContext(_options))
            {
                var repository = new ToDoItemRepositoryAsync(uow);
                var savedItem  = await repository.AddAsync(
                    new ToDoItem { Title = command.Title, Completed = command.Commpleted, Order = command.Order },
                    cancellationToken
                    );

                command.ToDoItemId = savedItem.Id;
            }

            _commandProcessor.Post(new TaskCreatedEvent(command.Title));
            return(await base.HandleAsync(command, cancellationToken));
        }
예제 #2
0
        public override async Task <BulkAddToDoCommand> HandleAsync(BulkAddToDoCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new ToDoContext(_options))
            {
                var repository = new ToDoItemRepositoryAsync(uow);
                foreach (var todo in command.ToDos)
                {
                    var savedItem = await repository.AddAsync(
                        new ToDoItem { Title = todo.Title, Completed = todo.Completed, Order = todo.Order },
                        cancellationToken
                        );

                    command.ToDoItemIds.Add(savedItem.Id);
                }

                return(await base.HandleAsync(command, cancellationToken));
            }
        }