Exemplo n.º 1
0
        public int CountUserSearchesByIp(string userIp)
        {
            using (MainAppDatabaseContext context = new MainAppDatabaseContext())
            {
                var selectUserCount = context.UserLog.Where(u => u.UserIp == userIp).Count();

                return(selectUserCount);
            }
        }
Exemplo n.º 2
0
        public IList <string> GetAllWords()
        {
            List <string> words = new List <string>();

            using (var context = new MainAppDatabaseContext())
            {
                var query = context.Words.Select(w => w.Word);
                words.AddRange(query);
            }
            return(words);
        }
Exemplo n.º 3
0
        public IList <string> FindAnagrams(string word)
        {
            List <string> anagrams = new List <string>();

            using (var context = new MainAppDatabaseContext())
            {
                var query = context.Words.Select(w => w.Word).Where(w => string.Join(string.Empty, word.OrderBy(a => a)) == string.Join(string.Empty, w.OrderBy(c => c)) && word != w);
                anagrams.AddRange(query);
            }
            return(anagrams);
        }
Exemplo n.º 4
0
        public IList <string> Find(string word)
        {
            List <string> words = new List <string>();

            using (var context = new MainAppDatabaseContext())
            {
                var query = context.Words.Select(w => w.Word).Where(w => w.Contains(word));
                words.AddRange(query);
            }
            return(words);
        }
Exemplo n.º 5
0
        public string Find(int wordId)
        {
            string word;

            using (var context = new MainAppDatabaseContext())
            {
                var query = context.Words.Where(w => w.Id == wordId).First();
                word = query.Word;
            }
            return(word);
        }
Exemplo n.º 6
0
        public List <UserLogReport> GetUserLogReport()
        {
            bool added = false;
            List <UserLogReport> userLogReports = new List <UserLogReport>();

            using (var context = new MainAppDatabaseContext())
            {
                var tempUserLogReport = context.UserLog.Join(context.CachedWords,
                                                             log => log.Word,
                                                             cache => cache.Word,
                                                             (log, cache) => new { log, cache })
                                        .Join(context.Words,
                                              o => o.cache.AnagramId,
                                              w => w.Id,
                                              (o, w) => new { o, w })
                                        .Select(r => new UserLogReport
                {
                    UserIp     = r.o.log.UserIp,
                    SearchTime = r.o.log.SearchTime,
                    Word       = r.o.log.Word,
                    Anagrams   = new List <string>()
                    {
                        r.w.Word
                    }
                });
                foreach (var tempUserLog in tempUserLogReport)
                {
                    added = false;
                    UserLogReport reportToAdd = new UserLogReport();
                    reportToAdd.UserIp     = tempUserLog.UserIp;
                    reportToAdd.SearchTime = tempUserLog.SearchTime;
                    reportToAdd.Word       = tempUserLog.Word;
                    foreach (var logReport in userLogReports)
                    {
                        if (logReport.UserIp == reportToAdd.UserIp && logReport.SearchTime == reportToAdd.SearchTime)
                        {
                            logReport.Anagrams.Add(tempUserLog.Anagrams[0]);
                            added = true;
                            break;
                        }
                    }
                    if (!added)
                    {
                        reportToAdd.Anagrams = tempUserLog.Anagrams;
                        userLogReports.Add(reportToAdd);
                    }
                }
            }

            return(userLogReports);
        }
Exemplo n.º 7
0
        public void Save(string ip, string word, DateTime time)
        {
            UserLog log = new UserLog();

            log.UserIp     = ip;
            log.Word       = word;
            log.SearchTime = time;

            using (var context = new MainAppDatabaseContext())
            {
                context.UserLog.Add(log);
                context.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public IList <string> GetCachedAnagrams(string word)
        {
            List <string> anagrams = new List <string>();

            using (var context = new MainAppDatabaseContext())
            {
                var query = context.CachedWords.Where(c => c.Word == word).Join(context.Words,
                                                                                cache => cache.AnagramId,
                                                                                w => w.Id,
                                                                                (cache, w) => w.Word);
                anagrams.AddRange(query);
            }
            return(anagrams);
        }
Exemplo n.º 9
0
 public void Save(string word, IEnumerable <string> anagrams)
 {
     using (var context = new MainAppDatabaseContext())
     {
         var wordId = context.Words.Where(w => anagrams.Contains(w.Word)).Select(i => i.Id);
         foreach (var id in wordId)
         {
             CachedWords cache = new CachedWords();
             cache.Word      = word;
             cache.AnagramId = id;
             context.CachedWords.Add(cache);
         }
         context.SaveChanges();
     }
 }