Example #1
0
            private async Task SetPath(Domain.Models.Directory directory)
            {
                directory.Id = Guid.NewGuid();

                if (!directory.ParentId.HasValue)
                {
                    directory.SetPath();
                }
                else
                {
                    var parentDirectory = await _db.Directories.FindAsync(directory.ParentId);

                    if (parentDirectory == null)
                    {
                        throw new EntityNotFoundException <Directory>("Parent Directory not found");
                    }

                    if (parentDirectory.ProjectId != directory.ProjectId)
                    {
                        throw new ConflictException("Parent and child Directories must be in the same Project");
                    }

                    directory.SetPath(parentDirectory.Path);
                }
            }
Example #2
0
            protected async Task UpdatePaths(Domain.Models.Directory directory, Guid?parentId)
            {
                string parentPath = null;
                string oldPath    = directory.Path;

                if (parentId.HasValue)
                {
                    var parentDirectory = await _db.Directories.FindAsync(parentId);

                    if (parentDirectory == null)
                    {
                        throw new EntityNotFoundException <Directory>("Parent Directory Not Found");
                    }

                    parentPath = parentDirectory.Path;
                }

                var descendants = await _db.Directories.GetChildren(directory, false).ToListAsync();

                directory.SetPath(parentPath);

                foreach (var desc in descendants)
                {
                    desc.Path = desc.Path.Replace(oldPath, directory.Path);
                }
            }