Exemplo n.º 1
0
 public async Task SaveUserLog(string ip, string searchWord, string connString)
 {
     using (var db = new AnagramContext(connString))
     {
         var userLogEntity = new UserLogEntity {
             UserIP = ip, LogDate = DateTime.UtcNow
         };
         userLogEntity.CachedWordEntity = db.CachedWordEntities.First(s => s.SearchWord == searchWord);
         db.UserLogEntities.Add(userLogEntity);
         await db.SaveChangesAsync();
     }
 }
Exemplo n.º 2
0
        public async Task <List <WordEntity> > CheckIfExistsInOrderedWords(string key, string connString)
        {
            using (var db = new AnagramContext(connString))
            {
                var query = await db.WordEntities.Where(s => s.OrderedWord == key).ToListAsync();

                if (query.Count() <= 0)
                {
                    return(new List <WordEntity>());
                }
                return(query);
            }
        }
Exemplo n.º 3
0
 public void AddFromFile(Dictionary <string, DictionaryEntry> dictionary, string connString)
 {
     using (var db = new AnagramContext(connString))
     {
         for (int i = 0; i < dictionary.Count; i++)
         {
             var item = dictionary.ElementAt(i);
             var word = new WordEntity {
                 Word = item.Key, OrderedWord = item.Value.Word, Category = item.Value.Antecedent
             };
             db.WordEntities.Add(word);
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public async Task AddToChaced(string searchWord, List <WordEntity> wordEntities, string connString)
        {
            using (var db = new AnagramContext(connString))
            {
                var cachedWordEntity = new CachedWordEntity {
                    SearchWord = searchWord,
                };

                foreach (var item in wordEntities)
                {
                    cachedWordEntity.WordEntities.Add(db.WordEntities.FirstOrDefault(m => m.WordId == item.WordId));
                }

                db.CachedWordEntities.Add(cachedWordEntity);
                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 5
0
        public async Task <Dictionary <string, DictionaryEntry> > FilterWords(string key, string connString)
        {
            var dictionary = new Dictionary <string, DictionaryEntry>();

            using (var db = new AnagramContext(connString))
            {
                var query = await db.WordEntities.Where(s => s.Word.StartsWith(key)).ToListAsync();

                foreach (var item in query)
                {
                    var element = new DictionaryEntry();
                    element.Word       = item.OrderedWord;
                    element.Antecedent = item.Category;
                    dictionary.Add(key: item.Word, value: element);
                }
            }
            return(dictionary);
        }
Exemplo n.º 6
0
        public async Task <Dictionary <string, DictionaryEntry> > GetWords(int key, int numberOfItemsToReturn, string connString)
        {
            var dictionary = new Dictionary <string, DictionaryEntry>();

            using (var db = new AnagramContext(connString))
            {
                var query = await db.WordEntities.Skip(numberOfItemsToReturn *(key - 1)).Take(numberOfItemsToReturn * key).ToListAsync();

                foreach (var item in query)
                {
                    var element = new DictionaryEntry();
                    element.Word       = item.OrderedWord;
                    element.Antecedent = item.Category;
                    dictionary.Add(key: item.Word, value: element);
                }
            }
            return(dictionary);
        }
Exemplo n.º 7
0
        public async Task <List <string> > GetCachedWords(string key, string connString)
        {
            var list = new List <string>();

            using (var db = new AnagramContext(connString))
            {
                var result = await db.CachedWordEntities.Include(r => r.WordEntities).Where(s => s.SearchWord == key).ToListAsync();

                if (result.Count() <= 0)
                {
                    return(list);
                }
                foreach (var wordEntity in result.Last().WordEntities)
                {
                    if (key != wordEntity.Word)
                    {
                        list.Add(wordEntity.Word);
                    }
                }
            }
            return(list);
        }