Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public Task <int> DeleteUserWordPairAsync(int userId, int userWordPairId)
        {
            // todo union.expect ??
            UserWordPair userWordsPair = userWordPairRepository
                                         .GetWhere(uwp => uwp.UserWordPairId.Equals(userWordPairId) && uwp.UserId.Equals(userId))
                                         .SingleOrDefault();

            return(userWordsPair != null?userWordPairRepository.Remove(userWordsPair) : new Task <int>(() => 0));
        }
Ejemplo n.º 3
0
        public static KnowledgeLicense GetLicense(this UserWordPair userWordPair)
        {
            var knowledgeLicense = new KnowledgeLicense
            {
                Period     = userWordPair.LearningPeriod,
                RepeatTime = userWordPair.TimeGap
            };

            return(knowledgeLicense);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Convert UserWorkPair to WordTranslation
        /// </summary>
        /// <param name="uwp"></param>
        /// <returns></returns>
        public static WordTranslation ToWordTranslations(this UserWordPair uwp)
        {
            Word foreign = uwp.WordPair.WordForeign;
            Word native  = uwp.WordPair.WordNative;

            WordTranslation addedWord = uwp.IsInvertPair
                ? new WordTranslation(native.Content, foreign.Content)
                : new WordTranslation(foreign.Content, native.Content);

            addedWord.ServerId = uwp.UserWordPairId;
            return(addedWord);
        }
Ejemplo n.º 5
0
        public static Memorization Memorization(this UserWordPair userWordPair)
        {
            if (userWordPair == null)
            {
                throw new ArgumentNullException(nameof(userWordPair));
            }
            Memorization memorization = new Memorization
            {
                Period     = userWordPair.LearningPeriod,
                RepeatTime = userWordPair.TimeGap
            };

            return(memorization);
        }
Ejemplo n.º 6
0
 public static UserWordPair SetLicense(this UserWordPair userWordPair, KnowledgeLicense knowledgeLicense)
 {
     userWordPair.LearningPeriod = knowledgeLicense.Period;
     userWordPair.TimeGap        = knowledgeLicense.RepeatTime;
     return(userWordPair);
 }