예제 #1
0
 public string FindWordByID(int wordID)
 {
     using (var context = new AnagramsEntities())
     {
         return(context.Words.Find(wordID)?.Word1);
     }
 }
예제 #2
0
 public List <string> GetData()
 {
     using (var context = new AnagramsEntities())
     {
         return(context.Words.Select(b => b.Word1).ToList());
     }
 }
예제 #3
0
 public List <string> GetFilteredWords(string fragment)
 {
     using (var context = new AnagramsEntities())
     {
         return(context.Words.Where(b => b.Word1.StartsWith(fragment)).Select(a => a.Word1).ToList());
     }
 }
예제 #4
0
 public string GetCachedWordByID(int cachedWordID)
 {
     using (var context = new AnagramsEntities())
     {
         return(context.CachedWords.Find(cachedWordID).CachedWord1);
     }
 }
예제 #5
0
 public List <UserLogFull> GetUserLogs()
 {
     using (var context = new AnagramsEntities())
     {
         List <UserLog> userLogs = context.UserLogs.ToList();
         return(userLogs.Select(a => new UserLogFull(a.IP_address, a.SearchTime, a.CachedWordID)).ToList());
     }
 }
예제 #6
0
 public List <int> GetCachedAnagrams(int cachedWordID)
 {
     using (var context = new AnagramsEntities())
     {
         return(context.CachedWords
                .SingleOrDefault(b => b.CachedWordID == cachedWordID).Words.Select(b => b.ID).ToList());
     }
 }
예제 #7
0
 public int FindWordID(string word)
 {
     using (var context = new AnagramsEntities())
     {
         return(context.Words
                .Where(b => b.Word1 == word)
                .FirstOrDefault().ID);
     }
 }
예제 #8
0
 public void AddNewWord(string word)
 {
     using (var context = new AnagramsEntities())
     {
         var newWord = new Word()
         {
             Word1 = word
         };
         context.Words.Add(newWord);
         context.SaveChanges();
     }
 }
예제 #9
0
 public void InsertIntoCashedWords(string word)
 {
     using (var context = new AnagramsEntities())
     {
         var cachedWord = new CachedWord()
         {
             CachedWord1 = word
         };
         context.CachedWords.Add(cachedWord);
         context.SaveChanges();
     }
 }
예제 #10
0
 public void InsertIntoCashedAnagrams(int cachedWordID, List <int> anagramsID)
 {
     using (var context = new AnagramsEntities())
     {
         var cachedWord = context.CachedWords.SingleOrDefault(b => b.CachedWordID == cachedWordID);
         if (cachedWord != null)
         {
             context.CachedWords.Attach(cachedWord);
             cachedWord.Words = context.Words.Where(b => anagramsID.Contains(b.ID)).ToList();
             context.SaveChanges();
         }
     }
 }
예제 #11
0
 public void AddUserLog(UserLogFull userLog)
 {
     using (var context = new AnagramsEntities())
     {
         var newUserLog = new UserLog()
         {
             IP_address   = userLog.IP_address,
             CachedWordID = userLog.CachedWordID,
             SearchTime   = userLog.Time
         };
         context.UserLogs.Add(newUserLog);
         context.SaveChanges();
     }
 }
예제 #12
0
 public int?GetCachedWordID(string word)
 {
     using (var context = new AnagramsEntities())
     {
         var cachedWord = context.CachedWords
                          .Where(b => b.CachedWord1 == word)
                          .FirstOrDefault();
         if (cachedWord == null)
         {
             return(null);
         }
         return(cachedWord.CachedWordID);
     }
 }
예제 #13
0
 public void DeleteWord(int wordID)
 {
     using (var context = new AnagramsEntities())
     {
         var itemToRemove = context.Words.SingleOrDefault(x => x.ID == wordID);
         if (itemToRemove != null)
         {
             context.Words.Remove(itemToRemove);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Such word doesnt exist");
         }
     }
 }
예제 #14
0
 public void UpdateWord(int wordID, string newWord)
 {
     using (var context = new AnagramsEntities())
     {
         var itemToUpdate = context.Words.SingleOrDefault(x => x.ID == wordID);
         if (itemToUpdate != null)
         {
             itemToUpdate.Word1       = newWord;
             itemToUpdate.CachedWords = null;
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Such word doesnt exist");
         }
     }
 }