Ejemplo n.º 1
0
        private ShuffleWord GetShuffleWord(long userId, long id)
        {
            ShuffleWord result =
                Adapter.ReadByContext(
                    c => c.ShuffleWord.FirstOrDefault(e => e.UserId == userId && e.WordTranslationId == id));

            return(result);
        }
Ejemplo n.º 2
0
        protected override List <SourceWithTranslation> GetNextById(long userId,
                                                                    long id,
                                                                    long sourceLanguageId,
                                                                    long translationLanguageId,
                                                                    int count)
        {
            ShuffleWord shuffleWord = GetShuffleWord(userId, id);

            if (shuffleWord == null)
            {
                return(new List <SourceWithTranslation>(0));
            }
            long shuffleWordId = shuffleWord.Id;

            List <SourceWithTranslation> result = Adapter.ReadByContext(c => {
                var joinedSequence = (from w1 in c.Word
                                      join wt in c.WordTranslation on w1.Id equals wt.WordId1
                                      join w2 in c.Word on wt.WordId2 equals w2.Id
                                      join sw in c.ShuffleWord on wt.Id equals sw.WordTranslationId
                                      where (sw.UserId == userId && sw.Id > shuffleWordId &&
                                             sw.Type == _shuffleType &&
                                             (w1.Type & _wordType) == _wordType && (w2.Type & _wordType) == _wordType &&
                                             ((w1.LanguageId == sourceLanguageId && w1.Pronunciation != null &&
                                               w2.LanguageId == translationLanguageId)
                                              ||
                                              (w1.LanguageId == translationLanguageId &&
                                               w2.LanguageId == sourceLanguageId && w2.Pronunciation != null)))
                                      orderby sw.Id ascending
                                      select new { sw.Id, sw.WordTranslationId, wt.Image, w1, w2 }).Take(count);
                return
                (joinedSequence.AsEnumerable().OrderBy(e => e.Id).Select(
                     e => ConverterEntities.ConvertToSourceWithTranslation(e.WordTranslationId, e.Image, sourceLanguageId, e.w1, e.w2)).
                 ToList());
            });

            return(result);
        }