diff --git a/Backend/Services/MergeService.cs b/Backend/Services/MergeService.cs index 9f40ed2621..86e669a232 100644 --- a/Backend/Services/MergeService.cs +++ b/Backend/Services/MergeService.cs @@ -34,22 +34,27 @@ private async Task MergePrepParent(string projectId, MergeWords mergeWords parent.ProjectId = projectId; parent.History = new List(); - // Add child to history. foreach (var childSource in mergeWords.Children) { + // Add child to history. parent.History.Add(childSource.SrcWordId); + if (childSource.GetAudio) { - var child = await _wordRepo.GetWord(projectId, childSource.SrcWordId); - if (child is null) + // Add child's audio. + var child = await _wordRepo.GetWord(projectId, childSource.SrcWordId) + ?? throw new KeyNotFoundException($"Unable to locate word: ${childSource.SrcWordId}"); + child.Audio.ForEach(pro => { - throw new KeyNotFoundException($"Unable to locate word: ${childSource.SrcWordId}"); - } - parent.Audio.AddRange(child.Audio); + if (parent.Audio.All(p => p.FileName != pro.FileName)) + { + parent.Audio.Add(pro); + } + }); } } - // Remove duplicates. + // Remove history duplicates. parent.History = parent.History.Distinct().ToList(); return parent; }