Ejemplo n.º 1
0
        public void DeleteQueueItem(QueueItem existingQueueItem, string driveName)
        {
            var attachments = _queueItemAttachmentRepository.Find(null, q => q.QueueItemId == existingQueueItem.Id)?.Items;

            if (attachments.Count != 0)
            {
                var fileView = new FileFolderViewModel();
                foreach (var attachment in attachments)
                {
                    fileView = _fileManager.DeleteFileFolder(attachment.FileId.ToString(), driveName);
                    _queueItemAttachmentRepository.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 DeleteQueueItem(QueueItem existingQueueItem, string driveId)
        {
            if (existingQueueItem == null)
            {
                throw new EntityDoesNotExistException("Queue item does not exist or you do not have authorized access.");
            }

            UpdateItemsStates(existingQueueItem.QueueId.ToString());

            //soft delete each queue item attachment entity and file entity that correlates to the queue item
            var attachments = _queueItemAttachmentRepository.Find(null, q => q.QueueItemId == existingQueueItem.Id)?.Items;

            if (attachments.Count != 0)
            {
                var fileView = new FileFolderViewModel();

                if (string.IsNullOrEmpty(driveId))
                {
                    if (attachments.Count() > 0)
                    {
                        var fileToDelete = _storageFileRepository.GetOne(attachments[0].FileId);
                        driveId = fileToDelete.StorageDriveId.ToString();
                    }
                    else
                    {
                        var drive = _storageDriveRepository.Find(null, q => q.IsDefault == true).Items?.FirstOrDefault();
                        driveId = drive.Id.ToString();
                    }
                }

                foreach (var attachment in attachments)
                {
                    fileView = _fileManager.DeleteFileFolder(attachment.FileId.ToString(), driveId, "Files");
                    _queueItemAttachmentRepository.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)
        {
            Guid      queueItemId       = new Guid(id);
            QueueItem existingQueueItem = repository.GetOne(queueItemId);

            if (existingQueueItem == null)
            {
                ModelState.AddModelError("QueueItem", "QueueItem cannot be found or does not exist.");
                return(NotFound(ModelState));
            }
            if (existingQueueItem.IsLocked)
            {
                ModelState.AddModelError("Delete", "Queue Item is locked at this time and cannot be deleted");
                return(BadRequest(ModelState));
            }

            await webhookPublisher.PublishAsync("QueueItems.QueueItemDeleted", existingQueueItem.Id.ToString(), existingQueueItem.Name).ConfigureAwait(false);

            var response = await base.DeleteEntity(id);

            _hub.Clients.All.SendAsync("sendnotification", "QueueItem deleted.");

            //soft delete each queue item attachment entity and binary object entity that correlates to the queue item
            var attachmentsList = queueItemAttachmentRepository.Find(null, q => q.QueueItemId == existingQueueItem.Id)?.Items;

            foreach (var attachment in attachmentsList)
            {
                queueItemAttachmentRepository.SoftDelete((Guid)attachment.Id);

                var existingBinary = binaryObjectRepository.GetOne(attachment.BinaryObjectId);
                if (existingBinary != null)
                {
                    await webhookPublisher.PublishAsync("Files.FileDeleted", existingBinary.Id.ToString(), existingBinary.Name).ConfigureAwait(false);
                }
                binaryObjectRepository.SoftDelete(attachment.BinaryObjectId);
            }

            return(response);
        }