public void AddNewWord(string word) { using (var context = new AnagramsEntities()) { var newWord = new Word() { Word1 = word }; context.Words.Add(newWord); context.SaveChanges(); } }
public void InsertIntoCashedWords(string word) { using (var context = new AnagramsEntities()) { var cachedWord = new CachedWord() { CachedWord1 = word }; context.CachedWords.Add(cachedWord); context.SaveChanges(); } }
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(); } } }
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(); } }
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"); } } }
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"); } } }