public async Task <FolderResponse> SaveAsync(Folder folder)
        {
            if (folder.ParentFolderId != null)
            {
                var existingFolder = await _folderRepository.FindByIdAsync(folder.ParentFolderId.Value);

                if (existingFolder == null)
                {
                    return(new FolderResponse("parent folder not found."));
                }
                else
                {
                    folder.ParentFolder = existingFolder;
                }
            }
            try
            {
                await _folderRepository.AddAsync(folder);

                await _unitOfWork.CompleteAsync();

                return(new FolderResponse(folder));
            }
            catch (Exception ex)
            {
                _logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(SaveAsync), ex);
                // Do some logging stuff
                return(new FolderResponse($"An error occurred when saving the folder: {ex.Message}"));
            }
        }
Esempio n. 2
0
        public async Task <IFolder> AddFolderAsync(IFolder folder, string name)
        {
            if (folder == null)
            {
                new ArgumentNullException(nameof(folder));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                new ArgumentNullException(nameof(name));
            }

            if (name.Contains("/"))
            {
                throw new ArgumentException("Cannot use path delimiter('/')", nameof(name));
            }

            var path  = folder.Path + name + "/";
            var added = await _folders.AddAsync(path);

            return(Mapping.Mapper.Map <Folder>(added));
        }