Exemplo n.º 1
0
        public async Task Create(params DirectoryModel[] directories)
        {
            foreach (var directory in directories)
            {
                if (directory.ParentId == null)
                {
                    throw new InvalidDataException("Parent directory not specified.");
                }

                var parentDirectory = await _directoryRepository.GetById(directory.ParentId.Value);

                if (parentDirectory == null)
                {
                    throw new NotFoundException("Parent directory not found.");
                }

                var dirToAdd = new Directory
                {
                    ParentId  = directory.ParentId,
                    Name      = directory.Name,
                    Private   = parentDirectory.Private || directory.Private,
                    StaffOnly = directory.StaffOnly
                };

                _directoryRepository.Create(dirToAdd);
            }

            await _directoryRepository.SaveChanges();
        }