public string FindWordByID(int wordID) { using (var context = new AnagramsEntities()) { return(context.Words.Find(wordID)?.Word1); } }
public List <string> GetData() { using (var context = new AnagramsEntities()) { return(context.Words.Select(b => b.Word1).ToList()); } }
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()); } }
public string GetCachedWordByID(int cachedWordID) { using (var context = new AnagramsEntities()) { return(context.CachedWords.Find(cachedWordID).CachedWord1); } }
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()); } }
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()); } }
public int FindWordID(string word) { using (var context = new AnagramsEntities()) { return(context.Words .Where(b => b.Word1 == word) .FirstOrDefault().ID); } }
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 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); } }
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"); } } }