public async Task DeleteMessageAsync(DeleteMessageRequest request) { var message = await UnitOfWork.MessageRepository.GetMessageByIdAsync(request.MessageId); Ensure.That(message).WithException(x => new NotFoundException(new ErrorDto(ErrorCode.NotFound, "Message does not exist."))).IsNotNull(); var owner = await UnitOfWork.MemberRepository.GetMemberBySaasUserIdAsync(request.SaasUserId); if (message.OwnerId != owner.Id) { throw new AccessForbiddenException(new ErrorDto(ErrorCode.ForbiddenError, "Access forbidden.")); } var messageAttachments = await UnitOfWork.AttachmentRepository.GetMessageAttachmentsAsync(message.Id); using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { // Delete message attachments from database await UnitOfWork.AttachmentRepository.DeleteMessageAttachmentsAsync(message.Id); // Delete message attachments from blob storage foreach (var attachment in messageAttachments) { await _contentStorage.DeleteContentAsync(attachment.FileName, _cloudStorageConfiguration.MessageAttachmentsContainer); } //TODO calculate previous message await UnitOfWork.ChannelMemberRepository.UpdateLastReadMessageAsync(message.Id); // Delete message from database await UnitOfWork.MessageRepository.DeleteMessageAsync(message.Id); transactionScope.Complete(); } }
public async Task ShouldSaveContentAsync() { Uri savedUrl = await SavedContentAsync(_fileName); var url = await _contentStorage.GetBlobUrlAsync(_fileName, _containerName); url.Should().Be(savedUrl); //Clear await _contentStorage.DeleteContentAsync(_fileName, _containerName); }
public async Task DeleteAttachmentAsync(Guid questionId) { var question = UnitOfWork.QuestionRepository.GetById(questionId); if (string.IsNullOrWhiteSpace(question.Image)) { return; } await _contentStorage.DeleteContentAsync(question.Image, PhotoContainerName); question.Image = null; UnitOfWork.QuestionRepository.Update(question); await UnitOfWork.SaveChangesAsync(); }