public async Task <IActionResult> Post([FromBody] WordData wordData) { wordData.CreationDate = DateTime.Now; wordData.Validated = false; _wordContext.Add(wordData); _wordContext.SaveChanges(); return(Ok(wordData)); }
public ActionResult Create([Bind(Include = "WordID,WordText")] Word word) { if (ModelState.IsValid) { db.Words.Add(word); db.SaveChanges(); Log.Information("A new tweet has been created."); return(RedirectToAction("Index")); } return(View(word)); }
public void AddToSampler(string userId, WordData wordData) { var user = _context.Users.FirstOrDefault(u => u.Id == userId); if (user.Sampler == null || user.Sampler.Length == 0) { user.Sampler = wordData.Word; } else { user.Sampler += "," + wordData.Word; } _context.Update(user); _context.SaveChanges(); }
/// <summary> /// The method adds a word with certain difficuly in the database /// </summary> /// <example> /// <code> /// WordAddBusiness.AddWord(word, out diff); /// </code> /// </example> /// <exception cref="HangManV2.Commons.WordAlreadyExistsExeption">Thrown when the word is already in the database /// <exception cref="HangManV2.Commons.WordUnplayableExeption">Thrown when the word is less than 3 symbols public static void AddWord(string word, out string difficulty) { try { CheckIfWordAlreadyInDB(word); } catch (WordAlreadyExistsExeption) { throw new WordAlreadyExistsExeption(); } try { CheckIfWordPlayable(word); } catch (WordUnplayableExeption) { throw new WordUnplayableExeption(); } difficulty = DetermineWordDifficulty(word); using (var dbcontext = new WordContext()) { word newWord = new Data.word(); newWord.Word1 = word; newWord.Difficulty = difficulty; dbcontext.Words.Add(newWord); dbcontext.SaveChanges(); } }
public void DeleteColod(int _id) { db = new ColodContext(); wordDb = new WordContext(); db.Colods.Load(); // загрузка данных wordDb.Words.Load(); ColodContext ColodContext = new ColodContext(); WordContext wordContext = new WordContext(); ModelColod card = ColodContext.Colods .Where(x => x.Id == _id) .FirstOrDefault(); ColodContext.Colods.Remove(card); ColodContext.SaveChanges(); ModelWord modelWord = wordContext.Words //удаление всех слов с таким же id колоды .Where(x => x.Colods == _id) .FirstOrDefault(); if (modelWord != null) { wordContext.Words.Remove(modelWord); wordContext.SaveChanges(); } }
public void Seed() { _wordContext.Texts.Add(new WordModel { Id = 1, Text = LoremIpsum }); _wordContext.SaveChanges(); }
/// <summary> /// Adds the specified word to the database. /// </summary> /// <param name="word">The word to add.</param> /// <owner>Mariia Yelisieieva</owner> public void Add(Word word) { using (var context = new WordContext()) { context.Words.Add(word); context.SaveChanges(); AllWords = context.Words.ToList(); } }
/// <summary> /// Removes the specified word from the database. /// </summary> /// <param name="word">The word to remove.</param> /// <owner>Mariia Yelisieieva</owner> public void Remove(Word word) { using (var context = new WordContext()) { var customer = context.Words.Single(x => x.Id == word.Id); context.Words.Remove(customer); context.SaveChanges(); AllWords = context.Words.ToList(); } }
private WordContext GetContextWithData() { var options = new DbContextOptionsBuilder <WordContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new WordContext(options); context.AddRange( new Word { Phrase = "GOOD", Code = "4663" }, new Word { Phrase = "BAD", Code = "223" }, new Word { Phrase = "NO", Code = "66" }, new Word { Phrase = "ON", Code = "66" }, new Word { Phrase = "ROOT", Code = "7668" }, new Word { Phrase = "SNOT", Code = "7668" }, new Word { Phrase = "OUT", Code = "688" }, new Word { Phrase = "NUT", Code = "688" } ); context.SaveChanges(); return(context); }
public void DeleteCard(int _id) { db = new WordContext(); db.Words.Load(); // загрузка данных WordContext WordContext = new WordContext(); ModelWord card = WordContext.Words .Where(x => x.Id == _id) .FirstOrDefault(); WordContext.Words.Remove(card); WordContext.SaveChanges(); }
public WordController(WordContext context) { db = context; if (!db.Words.Any()) { db.Words.Add(new Word { RussWord = "карта", EnglWord = "map" }); db.Words.Add(new Word { RussWord = "компьютер", EnglWord = "computer", AddRuss = "ЭВМ" }); db.SaveChanges(); } }
public void AddCard(string _word, string _translate, int _progress, int _colods, bool _isChecked) { db = new WordContext(); db.Words.Load(); // загрузка данных ModelWord AddCard = new ModelWord(); AddCard.Word = _word; AddCard.Translate = _translate; AddCard.IsChecked = _isChecked; AddCard.Progress = _progress; AddCard.Colods = _colods; db.Words.Add(AddCard); db.SaveChanges(); }
/// <summary> /// Updates the specified word from the database. /// </summary> /// <param name="word">The word with changed fields to update.</param> /// <owner>Mariia Yelisieieva</owner> public void Update(Word word) { using (var context = new WordContext()) { AllWords = context.Words.ToList(); Word wordToUpdate = AllWords.Single(x => x.Id == word.Id); wordToUpdate.Chinese = word.Chinese; wordToUpdate.Pinyin = word.Pinyin; wordToUpdate.English = word.English; wordToUpdate.Progress = word.Progress; context.SaveChanges(); } }
public IHttpActionResult PutWordOrPhrase(int id, [FromBody] WordOrPhrase editedWordOrPhrase) { if (editedWordOrPhrase.Id != id) { return(BadRequest()); } db.Entry(editedWordOrPhrase).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WordOrPhraseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Save() { db.SaveChanges(); }
public GenericRepositoryTestFixture() { var options = new DbContextOptionsBuilder <WordContext>() .UseInMemoryDatabase("MockGenericRepositoryDatabase") .Options; WordContext = new WordContext(options); var word = new Word { Name = "school", Level = Level.A1, Meanings = new List <Meaning>() { new Meaning { PartOfSpeech = PartOfSpeech.Noun, Definitions = new List <Definition>() { new Definition { Language = Language.English, Define = "An institution for educating children.", Example = "Ryder's children did not go to school at all.", Synonyms = new List <Synonym> { new Synonym("educational institution"), new Synonym("centre of learning") } }, new Definition { Language = Language.English, Define = "Any institution at which instruction is given in a particular discipline.", Example = "A dancing school" }, new Definition { Language = Language.English, Define = "A group of people, particularly writers, artists, or philosophers, " + "sharing the same or similar ideas, methods, or style.", Example = "The Frankfurt school of critical theory", Synonyms = new List <Synonym> { new Synonym("group"), new Synonym("set"), new Synonym("circle"), new Synonym("clique"), new Synonym("faction"), new Synonym("sect") } } } }, new Meaning() { PartOfSpeech = PartOfSpeech.Verb, Definitions = new List <Definition>() { new Definition { Language = Language.English, Define = "Send to school; educate.", Example = "he was schooled in Boston.", Synonyms = new List <Synonym> { new Synonym("educate"), new Synonym("teach"), new Synonym("instruct") } } } } } }; WordContext.Words.Add(word); word = new Word { Name = "run", Level = Level.A1, Meanings = new List <Meaning>() { new Meaning { PartOfSpeech = PartOfSpeech.Verb, Definitions = new List <Definition>() { new Definition { Language = Language.English, Define = "Move at a speed faster than a walk, " + "never having both or all the feet on the ground at the same time.", Example = "The dog ran across the road", Synonyms = new List <Synonym> { new Synonym("sprint"), new Synonym("race"), new Synonym("dart"), new Synonym("rush"), new Synonym("dash") } } } } } }; WordContext.Words.Add(word); word = new Word { Name = "company", Level = Level.A1, Meanings = new List <Meaning>() { new Meaning { PartOfSpeech = PartOfSpeech.Noun, Definitions = new List <Definition>() { new Definition { Language = Language.English, Define = "A commercial business.", Example = "A shipping company.", Synonyms = new List <Synonym> { new Synonym("firm"), new Synonym("business"), new Synonym("corporation"), new Synonym("house"), new Synonym("establishment") } }, new Definition { Language = Language.English, Define = "The fact or condition of being with another or others, " + "especially in a way that provides friendship and enjoyment.", Example = "I could do with some company.", Synonyms = new List <Synonym> { new Synonym("companionship"), new Synonym("presence"), new Synonym("friendship"), new Synonym("fellowship"), new Synonym("closeness") } }, new Definition { Language = Language.English, Define = "The fact or condition of being with another or others, " + "especially in a way that provides friendship and enjoyment.", Example = "I could do with some company.", Synonyms = new List <Synonym> { new Synonym("companionship"), new Synonym("presence"), new Synonym("friendship"), new Synonym("fellowship"), new Synonym("closeness"), new Synonym("amity") } } } }, new Meaning() { PartOfSpeech = PartOfSpeech.Verb, Definitions = new List <Definition>() { new Definition { Language = Language.English, Define = "Associate with; keep company with.", Example = "These men which have companied with us all this time" } } } } }; WordContext.Words.Add(word); WordContext.SaveChanges(); }