public async Task <IActionResult> CreateFolder(Guid Id, CreateFolderInput input)
        {
            var user = await _userService.TryGetUserAsync(UserId());

            var result = await _fileService.CreateFolderAsync(Id, input, user);

            return(result.Error switch
            {
                ErrorType.None => Ok(result.Data),
                ErrorType.NotFound => NotFound(result.Errors),
                ErrorType.Unauthorized => Unauthorized(result.Errors),
                _ => BadRequest()
            });
        public async Task <Result <CreateFolderResult> > CreateFolderAsync(Guid id, CreateFolderInput input, User user)
        {
            if (user == null)
            {
                return(new Result <CreateFolderResult>(false, null, "Unauthorized", ErrorType.Unauthorized));
            }

            if (input is null || id == Guid.Empty)
            {
                return(new Result <CreateFolderResult>(false, null, "Data is not received", ErrorType.BadRequest));
            }


            var folder = await _context
                         .Folders
                         .Include(x => x.Folders)
                         .FirstOrDefaultAsync(x => x.Id == id);

            var disk = await _context
                       .Disks
                       .Include(x => x.Owner)
                       .FirstOrDefaultAsync(x => x.OwnerId == user.Id && x.Id == folder.DiskHintId);

            if (folder == null)
            {
                return(new Result <CreateFolderResult>(false, null, "Parent folder not found", ErrorType.BadRequest));
            }

            if (disk == null)
            {
                return(new Result <CreateFolderResult>(false, null, "Disk not found", ErrorType.BadRequest));
            }

            var newFolder = new Folder(folder, user.Id, disk.Id, input.Name);

            await _context.AddAsync(newFolder);

            await _context.SaveChangesAsync();

            var result = new CreateFolderResult {
                Id = newFolder.Id, Name = newFolder.Name
            };

            return(new Result <CreateFolderResult>(true, result));
        }
Beispiel #3
0
 public async Task CreateFolder(CreateFolderInput input)
 {
     await _aliyunOSSManager.CreateFolder(input.BucketName, input.Folder, input.TagNames);
 }