public void DeleteAll(string emailId, string driveName) { var attachments = _emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(emailId))?.Items; if (attachments.Count != 0) { var fileView = new FileFolderViewModel(); foreach (var attachment in attachments) { fileView = _fileManager.DeleteFileFolder(attachment.FileId.ToString(), driveName); _emailAttachmentRepository.SoftDelete(attachment.Id.Value); } var folder = _fileManager.GetFileFolder(fileView.ParentId.ToString(), driveName); if (!folder.HasChild.Value) { _fileManager.DeleteFileFolder(folder.Id.ToString(), driveName); } else { _fileManager.AddBytesToFoldersAndDrive(new List <FileFolderViewModel> { fileView }); } } else { throw new EntityDoesNotExistException("No attachments found to delete"); } }
public void DeleteAll(string emailId, string driveId) { var attachments = _emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(emailId))?.Items; if (attachments.Count != 0) { if (string.IsNullOrEmpty(driveId)) { var fileToDelete = _storageFileRepository.GetOne(attachments[0].FileId.Value); driveId = fileToDelete.StorageDriveId.ToString(); } var fileView = new FileFolderViewModel(); foreach (var attachment in attachments) { fileView = _fileManager.DeleteFileFolder(attachment.FileId.ToString(), driveId, "Files"); _emailAttachmentRepository.SoftDelete(attachment.Id.Value); } var folder = _fileManager.GetFileFolder(fileView.ParentId.ToString(), driveId, "Folders"); if (!folder.HasChild.Value) { _fileManager.DeleteFileFolder(folder.Id.ToString(), driveId, "Folders"); } else { _fileManager.RemoveBytesFromFoldersAndDrive(new List <FileFolderViewModel> { fileView }); } } else { throw new EntityDoesNotExistException("No attachments found to delete"); } }
public async Task <IActionResult> Delete(string id) { var attachments = emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(id))?.Items; if (attachments.Count != 0) { foreach (var attachment in attachments) { emailAttachmentRepository.SoftDelete((Guid)attachment.Id); binaryObjectRepository.SoftDelete((Guid)attachment.BinaryObjectId); } } return(await base.DeleteEntity(id)); }