public async Task CreateAsync(string name, int?parentId = null, string parentName = null) { if (parentId == null && parentName != null) // required for DatainitIalizer service { var parent = await _directoryRepository.GetOrFailAsync(parentName); parentId = parent.Id; } else if (parentId != null) { await _directoryRepository.GetOrFailAsync((int)parentId); } var directoryChildren = await GetNodeOfFirstLevelChilrenAsync(parentId); if (directoryChildren.Any(x => x.Name == name)) { throw new Exception($"The folder with name '{name}' already exist in the current directory."); } var directory = new Directory(name, parentId); await _directoryRepository.AddAsync(directory); }