public async Task <IActionResult> CreateFolder([FromBody] FolderRequest folder)
        {
            if (string.IsNullOrEmpty(folder.Name))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            try
            {
                GoNorthProject project = await _projectDbAccess.GetDefaultProject();

                FlexFieldFolder newFolder = new FlexFieldFolder {
                    ProjectId      = project.Id,
                    ParentFolderId = folder.ParentId,
                    Name           = folder.Name,
                    Description    = folder.Description
                };
                newFolder = await _folderDbAccess.CreateFolder(newFolder);

                await _timelineService.AddTimelineEntry(FolderCreatedEvent, folder.Name);

                return(Ok(newFolder.Id));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not create folder {0}", folder.Name);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
        public async Task <IActionResult> Folders(string parentId, int start, int pageSize)
        {
            string folderName     = string.Empty;
            string parentFolderId = string.Empty;
            Task <List <FlexFieldFolder> > queryTask;
            Task <int> countTask;

            if (string.IsNullOrEmpty(parentId))
            {
                GoNorthProject project = await _projectDbAccess.GetDefaultProject();

                queryTask = _folderDbAccess.GetRootFoldersForProject(project.Id, start, pageSize);
                countTask = _folderDbAccess.GetRootFolderCount(project.Id);
            }
            else
            {
                FlexFieldFolder folder = await _folderDbAccess.GetFolderById(parentId);

                parentFolderId = folder.ParentFolderId;
                folderName     = folder.Name;
                queryTask      = _folderDbAccess.GetChildFolders(parentId, start, pageSize);
                countTask      = _folderDbAccess.GetChildFolderCount(parentId);
            }

            Task.WaitAll(queryTask, countTask);

            FolderQueryResult queryResult = new FolderQueryResult();

            queryResult.FolderName = folderName;
            queryResult.ParentId   = parentFolderId;
            queryResult.Folders    = queryTask.Result;
            queryResult.HasMore    = start + queryResult.Folders.Count < countTask.Result;
            return(Ok(queryResult));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> DeleteFolder(string id)
        {
            FlexFieldFolder folder = await _folderDbAccess.GetFolderById(id);

            bool isFolderEmpty = await IsFolderEmpty(folder);

            if (!isFolderEmpty)
            {
                _logger.LogInformation("Attempted to delete non empty folder {0}.", folder.Name);
                return(StatusCode((int)HttpStatusCode.InternalServerError, _localizer["FolderNotEmpty"].Value));
            }

            await _folderDbAccess.DeleteFolder(folder);

            _logger.LogInformation("Folder was deleted.");

            if (!string.IsNullOrEmpty(folder.ImageFile))
            {
                _imageAccess.CheckAndDeleteUnusedImage(folder.ImageFile);
            }

            if (!string.IsNullOrEmpty(folder.ThumbnailImageFile))
            {
                _imageAccess.CheckAndDeleteUnusedImage(folder.ThumbnailImageFile);
            }

            await _timelineService.AddTimelineEntry(FolderDeletedEvent, folder.Name);

            return(Ok(id));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UploadFolderImage(string id)
        {
            // Validate Date
            string validateResult = this.ValidateImageUploadData();

            if (validateResult != null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer[validateResult]));
            }

            IFormFile       uploadFile   = Request.Form.Files[0];
            FlexFieldFolder targetFolder = await _folderDbAccess.GetFolderById(id);

            if (targetFolder == null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["CouldNotUploadImage"]));
            }

            // Save Image
            string objectImageFile = string.Empty;

            try
            {
                using (Stream imageStream = _imageAccess.CreateFlexFieldObjectImage(uploadFile.FileName, out objectImageFile))
                {
                    uploadFile.CopyTo(imageStream);
                }

                string thumbnailFilename = GenerateThumbnailFilename(objectImageFile);
                if (!_thumbnailService.GenerateThumbnail(objectImageFile, thumbnailFilename))
                {
                    thumbnailFilename = null;
                }

                string oldImageFile          = targetFolder.ImageFile;
                string oldThumbnailImageFile = targetFolder.ThumbnailImageFile;
                targetFolder.ImageFile          = objectImageFile;
                targetFolder.ThumbnailImageFile = thumbnailFilename;

                await _folderDbAccess.UpdateFolder(targetFolder);

                if (!string.IsNullOrEmpty(oldImageFile))
                {
                    _imageAccess.CheckAndDeleteUnusedImage(oldImageFile);
                }

                if (!string.IsNullOrEmpty(oldThumbnailImageFile))
                {
                    _imageAccess.CheckAndDeleteUnusedImage(oldThumbnailImageFile);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not upload image");
                return(StatusCode((int)HttpStatusCode.InternalServerError, _localizer["CouldNotUploadImage"]));
            }

            return(Ok(objectImageFile));
        }
        /// <summary>
        /// Checks if a folder is empty
        /// </summary>
        /// <param name="folder">Folder to check</param>
        /// <returns>True if the folder is empty, else false</returns>
        private async Task <bool> IsFolderEmpty(FlexFieldFolder folder)
        {
            int childFolderCount = await _folderDbAccess.GetChildFolderCount(folder.Id);

            if (childFolderCount > 0)
            {
                return(false);
            }

            return(true);
        }
        public async Task <IActionResult> UpdateFolder(string id, [FromBody] FolderRequest folder)
        {
            FlexFieldFolder loadedFolder = await _folderDbAccess.GetFolderById(id);

            loadedFolder.Name = folder.Name;

            await _folderDbAccess.UpdateFolder(loadedFolder);

            _logger.LogInformation("Folder was updated.");
            await _timelineService.AddTimelineEntry(FolderUpdatedEvent, folder.Name);

            return(Ok(id));
        }