public void DeleteDocument(string parentSubPath, ProjectItemType type, string documentName)
        {
            var fileName = "";

            if (type == ProjectItemType.Page)
            {
                fileName = $"{documentName}.{Constants.ProjectItemFileExtensions.Page}";
            }
            if (type == ProjectItemType.Workflow)
            {
                fileName = $"{documentName}.{Constants.ProjectItemFileExtensions.Workflow}";
            }
            var filePath = Path.Combine(Path.GetDirectoryName(_projectFilePath), parentSubPath, fileName);

            if (!File.Exists(filePath))
            {
                throw new ArgumentException($"A {type.ToString()} named '{fileName}' does not exist in this directory and cannot be deleted!");
            }

            _cmdProcessor.Execute(DeleteDocumentCommand.Create(_outputService, _projectFilePath, parentSubPath, fileName));

            ProjectItemChanged?.Invoke(new ProjectItemChangedArgs
            {
                ItemType      = type,
                Change        = ProjectItemChange.Delete,
                ItemName      = documentName,
                ParentSubPath = parentSubPath
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> Delete(Guid documentId, CancellationToken cancellationToken)
        {
            var documentQuery = new DocumentQuery(documentId);
            var document      = await Mediator.Send(documentQuery, cancellationToken);

            if (document == null)
            {
                return(NotFound("Document not found"));
            }

            var deleteDocumentCommand = DeleteDocumentCommand.Create(document);
            await Mediator.Send(deleteDocumentCommand, cancellationToken);

            return(NoContent());
        }