Ejemplo n.º 1
0
        public async Task AddFolder(AddFolderDto folderDto, int userId, int clientId)
        {
            var fileStorageRepository = DataContextManager.CreateRepository <IFileStorageRepository>();

            var parentFileStorage = await fileStorageRepository.GetById(folderDto.ParentId, userId, clientId);

            if (parentFileStorage == null || parentFileStorage != null && !parentFileStorage.IsDirectory)
            {
                throw new NotFoundException("File storage", folderDto.ParentId);
            }

            var childFileStorages = await fileStorageRepository.GetByParentId(parentFileStorage.Id, userId, clientId);

            if (childFileStorages.Any(x => x.IsDirectory && x.Name.Equals(folderDto.Name)))
            {
                throw new FoundSameObjectException("File storage", folderDto.Name);
            }

            var owners = await _permissionHelper.GetOwners(parentFileStorage, userId, clientId);

            var newFileStorage = new FileStorage
            {
                IsDirectory         = true,
                Name                = folderDto.Name,
                CreateDate          = DateTime.UtcNow,
                ParentFileStorageId = parentFileStorage.Id,
                CreateById          = userId,
                ClientId            = owners.ClientId,
                OwnerId             = owners.OwnerId,
                IsActive            = true
            };

            await fileStorageRepository.Add(newFileStorage);
        }
        public async Task <ActionResult> AddFolder([FromBody] AddFolderDto folderDto)
        {
            if (!IsAvailableOperation())
            {
                return(BadRequest());
            }

            await _fileStorageService.AddFolder(folderDto, UserId, ClientId);

            AddLog(Enums.LogType.Create, LogMessage.CreateSuccessByNameMessage(LogMessage.FolderEntityName, folderDto.Name, LogMessage.CreateAction, UserId));
            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <ApiResult <GetFolderDto> > AddFolder(AddFolderDto addFolder)
        {
            var currentUser = await userService.GetCurrentUser();

            var parentFolder = await foldersStorage.GetFolder(
                new FolderIdentity(addFolder.ParentId, currentUser.Id),
                CancellationToken.None);

            var newFolderId = new FolderIdentity(Guid.NewGuid(), currentUser.Id);
            var newFolder   = await foldersStorage.AddFolder(
                new Folder(newFolderId, addFolder.Name, parentFolder.Id,
                           parentFolder.ParentsPath.Concat(parentFolder.Id.AsArray()).ToList()),
                CancellationToken.None);

            return(ApiResult.SuccessResultWithData(newFolder.ToDto()));
        }