Example #1
0
        public async Task AddOne_GetAllReturnsIt()
        {
            var example = CreateExample("table", "стол");
            await _repo.Add(example);

            var all = await _repo.GetAll(new[] { example.Id });

            Assert.AreEqual(1, all.Count);
            var read = all.First();

            Assert.AreEqual(example.OriginPhrase, read.OriginPhrase);
            Assert.AreEqual(example.OriginWord, read.OriginWord);
            Assert.AreEqual(example.TranslatedPhrase, read.TranslatedPhrase);
            Assert.AreEqual(example.TranslatedWord, read.TranslatedWord);
        }
Example #2
0
        private async Task IncludeExamples(IReadOnlyCollection <UserWord> words)
        {
            var ids = new List <ObjectId>();

            foreach (var word in words)
            {
                foreach (var translation in word.Translations)
                {
                    ids.AddRange(translation.Examples.Select(e => e.ExampleId));
                }
            }

            var examples = (await _examplesRepo.GetAll(ids)).ToDictionary(e => e.Id);

            foreach (var word in words)
            {
                foreach (var translation in word.Translations)
                {
                    foreach (var example in translation.Examples)
                    {
                        example.ExampleOrNull = examples[example.ExampleId];
                    }
                }
            }
        }
Example #3
0
        public async Task <IReadOnlyList <DictionaryTranslation> > GetTranslationsWithExamples(string enword)
        {
            var word = await _dicRepository.GetOrDefault(enword);

            if (word == null)
            {
                return(new DictionaryTranslation[0]);
            }

            var result = new List <DictionaryTranslation>();

            foreach (var translation in word.Translations)
            {
                var examples = translation.Examples.Length > 0
                    ? await _exampleRepository.GetAll(translation.Examples.Select(e => e.ExampleId))
                    : new List <Example>();

                result.Add(new DictionaryTranslation(
                               word.Word,
                               translation.Word,
                               word.Transcription,
                               word.Source, examples));
            }

            return(result);
        }