Beispiel #1
0
        private async Task <SyncBase> AddUserWordPairAsync(int userId, WordTranslation wordTranslation)
        {
            // add word pair in repository
            WordPair wordPair = await AddPairAsync(wordTranslation).ConfigureAwait(false);

            // Load a word from a cell of a foreign word
            Word wordForeign = await wordRepository.FindById(wordPair.WordForeignId).ConfigureAwait(false);

            // If the loaded foreign word does not match the word
            // in the repository then the pair is considered inverted
            var createdPair = new UserWordPair
            {
                WordPairId   = wordPair.WordPairId,
                IsInvertPair = !wordForeign.Content.Equals(wordTranslation.WordForeign.ToLower()),
                UserId       = userId
            };

            // add pair to user dictionary
            createdPair = await userWordPairRepository.Stack(createdPair).ConfigureAwait(false);

            // create answer
            var resultPair = new SyncBase
            {
                Id       = wordTranslation.Id,
                ServerId = createdPair.UserWordPairId
            };

            return(resultPair);
        }