//method for getting all words public async Task <List <Word> > Get() { using var context = new WordDataContext(_dbContextOptions); var words = await context.Words.ToListAsync(); return(words?.Count > 0 ? words : null); }
public string Put(int id) { WordDataContext Wdc = new WordDataContext(); WordList wordList = new WordList() { Id = 1, Language = "French", Words = new List <Word>() }; Word testWord = new Word(); testWord.Id = 5; testWord.NativeLanguage = "mister"; testWord.TypeOfSpeech = TypeOfSpeech.Noun; testWord.ForeignLanguage = "monsieur"; wordList.Words.Add(testWord); Wdc.WordLists.Add(wordList); Wdc.SaveChanges(); string jsonData = JsonConvert.SerializeObject(wordList); return(jsonData.ToString()); }
public WordsController(WordDataContext context) { _context = context; }
//methond for updating existing word entity public void Update(Word entity) { using var context = new WordDataContext(_dbContextOptions); context.Words.Update(entity); context.SaveChanges(); }
//method for retrieving single record based on word value public async Task <Word> Get(string word) { using var context = new WordDataContext(_dbContextOptions); return(await context.Words.SingleOrDefaultAsync(w => w.Value == word)); }
public DuolingoUsersController(WordDataContext context) { _context = context; dupContext = _context; }