Exemplo n.º 1
0
 public void AddNewWord(string word)
 {
     using (var context = new AnagramsEntities())
     {
         var newWord = new Word()
         {
             Word1 = word
         };
         context.Words.Add(newWord);
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public void InsertIntoCashedWords(string word)
 {
     using (var context = new AnagramsEntities())
     {
         var cachedWord = new CachedWord()
         {
             CachedWord1 = word
         };
         context.CachedWords.Add(cachedWord);
         context.SaveChanges();
     }
 }
Exemplo n.º 3
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();
         }
     }
 }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
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");
         }
     }
 }
Exemplo n.º 6
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");
         }
     }
 }