public List<Word> GetAllWords() { using (var context = new WorldOfWordsDatabaseContext()) { return context.Words.ToList(); } }
/// <summary> /// Returns a list of all languages in the database. /// </summary> /// <returns></returns> public List<Language> GetAllLanguages() { using (var context = new WorldOfWordsDatabaseContext()) { return context.Languages.ToList(); } }
public List<Word> GetAllWordsBySpecificLanguage(int languageId) { using (var context = new WorldOfWordsDatabaseContext()) { return (from words in context.Words where words.LanguageId == languageId select words).ToList(); } }
public List<Enrollment> GetByGroupId(int groupId) { using (var context = new WorldOfWordsDatabaseContext()) { return context.Enrollments.Where(e => e.GroupId == groupId).Include(e => e.User).OrderBy(e => e.User.Name).ToList(); } }
public Group GetById(int groupId, int userId) { using (var context = new WorldOfWordsDatabaseContext()) { return context.Groups.Where(g => g.OwnerId == userId).Include(g => g.Course).FirstOrDefault(g => g.Id == groupId); } }
public int GetAmountOfWordTranslationsByLanguage(int langID) { using (var context = new WorldOfWordsDatabaseContext()) { return context.WordTranslations.Where(item => item.OriginalWord.LanguageId == langID).Count(); } }
public List<Group> GetAll(int userId) { using (var context = new WorldOfWordsDatabaseContext()) { return context.Groups.Where(g => g.OwnerId == userId).Include(group => group.Course).ToList(); } }
public Word GetWordById(int id) { using(var context = new WorldOfWordsDatabaseContext()) { return context.Words.Where(item => item.Id == id).FirstOrDefault(); } }
public void Add(IncomingUser user) { using (var context = new WorldOfWordsDatabaseContext()) { context.IncomingUsers.AddOrUpdate(user); context.SaveChanges(); } }
public void Delete(int courseId) { using (var context = new WorldOfWordsDatabaseContext()) { context.Courses.Remove(context.Courses.First(x => x.Id == courseId)); context.SaveChanges(); } }
public bool CheckIfGroupNameExists(GroupModel groupModel) { using (var context = new WorldOfWordsDatabaseContext()) { var group = context.Groups.FirstOrDefault(g => g.Name == groupModel.Name); return group != null; } }
public int Add(Tag tag) { using (var context = new WorldOfWordsDatabaseContext()) { context.Tags.Add(tag); context.SaveChanges(); return tag.Id; } }
public int Exists(string name) { using (var context = new WorldOfWordsDatabaseContext()) { var tag = context.Tags.FirstOrDefault(t => t.Name == name); return tag != null ? tag.Id : 0; } }
public int Add(WordSuite wordSuite) { using (var context = new WorldOfWordsDatabaseContext()) { context.WordSuites.AddOrUpdate(wordSuite); context.SaveChanges(); return wordSuite.Id; } }
public int Add(WordTranslation wordTranslation) { using (var context = new WorldOfWordsDatabaseContext()) { context.WordTranslations.Add(wordTranslation); context.SaveChanges(); return wordTranslation.Id; } }
public void ChangePassword(ForgotPasswordUserModel model) { using (var context = new WorldOfWordsDatabaseContext()) { var targetUser = context.Users.First(user => user.Id.ToString() == model.Id); targetUser.Password = _passwordHasher.HashPassword(model.Password); context.SaveChanges(); } }
public int GetAmountOfWordsBySearchValues(string searchValue, int languageId) { using (var context = new WorldOfWordsDatabaseContext()) { return context.WordTranslations .Where(w => w.OriginalWord.LanguageId == languageId && (w.OriginalWord.Value.Contains(searchValue) || w.TranslationWord.Value.Contains(searchValue))) .Count(); } }
public bool Add(GroupModel groupModel) { using (var context = new WorldOfWordsDatabaseContext()) { var newGroup = _mapper.MapToGroup(groupModel); context.Groups.Add(newGroup); context.SaveChanges(); return true; } }
public bool IsStudentWord(WordProgress wordProgress) { using (var context = new WorldOfWordsDatabaseContext()) { return context .WordProgresses .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId && wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord; } }
public List<Course> GetAllCourses(int userId) { using (var context = new WorldOfWordsDatabaseContext()) { return context.Courses. Where(c => c.OwnerId == userId). Include(course => course.WordSuites). Include(course => course.Language).ToList(); } }
public int Add(Course course, List<int> wordSuitesId) { using (var context = new WorldOfWordsDatabaseContext()) { context.Courses.Add(course); context.SaveChanges(); AddWordSuitesToCourse(course.Id, wordSuitesId); context.SaveChanges(); return course.Id; } }
public void AddToken(IncomingUser user) { if (Exists(user)) { using (var context = new WorldOfWordsDatabaseContext()) { var searchedUser = context.IncomingUsers.First(e => e.Id == user.Id); searchedUser.Token = user.Token; context.SaveChanges(); } } }
public bool Delete(int id) { using (var context = new WorldOfWordsDatabaseContext()) { var wordProgresses = context.WordProgresses; wordProgresses.RemoveRange(wordProgresses.Where(wp => wp.WordSuiteId == id)); var wordSuites = context.WordSuites; wordSuites.Remove(wordSuites.FirstOrDefault(ws => ws.Id == id)); context.SaveChanges(); return true; } }
public bool IncrementProgress(int wordSuiteId, int wordTranslationId) { using (var context = new WorldOfWordsDatabaseContext()) { var wordProgress = context.WordProgresses.First(x => (x.WordSuiteId == wordSuiteId && x.WordTranslationId == wordTranslationId)); ++(wordProgress.Progress); context.WordProgresses.AddOrUpdate(wordProgress); context.SaveChanges(); return true; } }
public Course GetById(int id, int userId) { Course course; using (var context = new WorldOfWordsDatabaseContext()) { course = context.Courses. Include(x => x.WordSuites.Select(wp => wp.WordProgresses)). Include(x => x.Language). First(x => x.Id == id); } course.WordSuites = course.WordSuites.Where(x => (x.OwnerId == userId && x.PrototypeId != null)).ToList(); return course; }
public bool AddRange(List<WordProgress> wordProgressRange) { using (var context = new WorldOfWordsDatabaseContext()) { var wordProgresses = context.WordProgresses; foreach (var wordProgress in wordProgressRange) { wordProgresses.AddOrUpdate(wordProgress); } context.SaveChanges(); return true; } }
public int Add(Word word) { using (var context = new WorldOfWordsDatabaseContext()) { if (Exists(word.Value, word.LanguageId) > 0) { return -1; } context.Words.Add(word); context.SaveChanges(); return word.Id; } }
public void EditCourse(Course courseModel, List<int> wordSuitesId) { using (var context = new WorldOfWordsDatabaseContext()) { var course = context.Courses.First(x => x.Id == courseModel.Id); course.Name = courseModel.Name; var wordSuites = course.WordSuites. Where(ws => (!wordSuitesId.Contains(ws.Id) && ws.PrototypeId == null)).ToList(); RemoveWordSuitesFromCourse(course.Id, wordSuites); wordSuitesId.RemoveAll(x => course.WordSuites.Select(ws => ws.Id).Contains(x)); AddWordSuitesToCourse(course.Id, wordSuitesId); context.SaveChanges(); } }
public WordSuite GetByID(int id) { WordSuite wordSuite; using (var context = new WorldOfWordsDatabaseContext()) { wordSuite = context .WordSuites .Include(ws => ws.Language) .Include(ws => ws.WordProgresses.Select(wp => wp.WordTranslation).Select(wt => wt.OriginalWord)) .Include(ws => ws.WordProgresses.Select(wp => wp.WordTranslation).Select(wt => wt.TranslationWord)) .First(x => x.Id == id); } return wordSuite; }
/// <summary> /// Adds a new language to the database. /// </summary> /// <param name="language">The language to be added to the database.</param> /// <returns>The id of a new database record, or -1, if such language already exists.</returns> public int AddLanguage(Language language) { using (var context = new WorldOfWordsDatabaseContext()) { if (context .Languages .Any(l => l.Name == language.Name)) { return -1; } context.Languages.Add(language); context.SaveChanges(); return language.Id; } }