Ejemplo n.º 1
0
        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");
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }
Ejemplo n.º 3
0
        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));
        }