public async Task <None> HandleAsync(DeleteTransaction request, CancellationToken cancellationToken) { var item = await _dataStorage.GetAsync(request.Key, cancellationToken); await _dataStorage.DeleteAsync(item, cancellationToken); return(None.Value); }
private Transaction MakeDeleteTransaction <T>(params T[] items) { var transaction = new DeleteTransaction(); foreach (var item in items) { var packed = CachedObject.Pack(item, _typeDescription); transaction.ItemsToDelete.Add(packed); } return(transaction); }
public async Task DeleteTransactionAsync(DeleteTransaction command) { Transaction firstTransaction = null; if (command.Id != null) { firstTransaction = await this.transactionRepository.GetTransactionAsync(command.Id.Value); } else if (command.ExternalId != null) { firstTransaction = await this.transactionRepository.GetTransactionAsync(command.ExternalId.Value); } else { throw new ArgumentException("No Transaction to remove"); } Transaction secondTransaction = null; var transfer = await this.transactionRepository.GetTransferAsync(firstTransaction.Id); var tags2Transaction = await this.tagRepository.GetTagToTransactionsAsync(firstTransaction.Id); await this.tagRepository.RemoveAsync(tags2Transaction); var files = this.Context.FilesToTransactions.Where(x => x.TransactionId == firstTransaction.Id && !x.IsDeleted).Select(x => x.FileId).ToList(); foreach (var fileId in files) { await fileService.RemoveFileAsync(fileId); } if (transfer != null) { var secondTRansactionId = transfer.ToTransactionId != firstTransaction.Id ? transfer.ToTransactionId : transfer.FromTransactionId; secondTransaction = await this.transactionRepository.GetTransactionAsync(secondTRansactionId); tags2Transaction = await this.tagRepository.GetTagToTransactionsAsync(secondTRansactionId); await this.tagRepository.RemoveAsync(tags2Transaction); await transactionRepository.RemoveTransferAsync(transfer); await transactionRepository.RemoveTransactionAsync(secondTransaction); } await transactionRepository.RemoveTransactionAsync(firstTransaction); }
public async Task DeleteTransactionAsync(DeleteTransaction command) { Transaction firstTransaction = null; if (command.Id != null) { firstTransaction = await this.transactionRepository.GetTransactionAsync(command.Id.Value); } else if (command.ExternalId != null) { firstTransaction = await this.transactionRepository.GetTransactionAsync(command.ExternalId.Value.ToString()); } else { throw new ArgumentException("No Transaction to remove"); } await this.fileRepository.RemoveAsync(firstTransaction.FilesToTransaction); Transaction secondTransaction = null; var transfer = await this.transactionRepository.GetTransferAsync(firstTransaction.Id); var tags2Transaction = await this.tagRepository.GetTagToTransactionsAsync(firstTransaction.Id); await this.tagRepository.RemoveAsync(tags2Transaction); if (transfer != null) { var secondTRansactionId = transfer.ToTransactionId != firstTransaction.Id ? transfer.ToTransactionId : transfer.FromTransactionId; secondTransaction = await this.transactionRepository.GetTransactionAsync(secondTRansactionId); tags2Transaction = await this.tagRepository.GetTagToTransactionsAsync(secondTRansactionId); await this.tagRepository.RemoveAsync(tags2Transaction); await transactionRepository.RemoveTransferAsync(transfer); await transactionRepository.RemoveTransactionAsync(secondTransaction); } await transactionRepository.RemoveTransactionAsync(firstTransaction); }
public async Task <IActionResult> Delete([FromBody] DeleteTransaction command) { await DispatchAsync(command); return(await GetAll()); }