コード例 #1
0
        public async Task <UserWord> AddWord(Word word, string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new EmptyUserIdException();
            }

            if (string.IsNullOrEmpty(word.Spelling))
            {
                throw new EmptySpellingException();
            }

            Word currentWord = await _wordRepository.GetWord(word.Id) ?? (await _wordRepository.GetWord(word.Spelling) ?? await _wordRepository.AddWord(word));

            UserWord userWord = await _learningRepository.GetUserWord(currentWord.Id, userId) ??
                                await _learningRepository.AddUserWord(new UserWord
            {
                WordId = currentWord.Id,
                UserId = userId
            });

            return(userWord);
        }