public BookWordDto(BookWord bookWord) { this.id = bookWord.Id; this.book = bookWord.BookId; this.word = bookWord.WordId; this.speachPart = bookWord.SpeachPart; }
public BookWordDto(BookWord bookWord) { this.id = bookWord.Id; this.book = bookWord.BookId; this.word = bookWord.WordId; this.speachPart = bookWord.SpeachPart; }
public async Task<IHttpActionResult> PostBookWord(BookWord bookword) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.BookWords.Add(bookword); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = bookword.Id }, bookword); }
public async Task <Tuple <BookWord, Translation> > AddTranslation(int bookID, int wordID, string value, LanguageType language, SpeachPartType speachPart) { // . search for BookWord BookWord bookWordEntity = await BookWords.Include("Translations").SingleOrDefaultAsync(bw => bw.BookId == bookID && bw.WordId == wordID && bw.SpeachPart == (int)speachPart); Translation translationEntity = null; if (bookWordEntity == null) { // . create BookWord if not exists bookWordEntity = new BookWord { BookId = bookID, WordId = wordID, SpeachPart = (int)speachPart }; BookWords.Add(bookWordEntity); await SaveChangesAsync(); } else { // . search for Translation translationEntity = bookWordEntity.Translations.SingleOrDefault(t => t.Value == value && t.Language == (int)language); } // . add Translation if not exists if (translationEntity == null) { translationEntity = new Translation { BookWordId = bookWordEntity.Id, Value = value, Language = (byte)language }; Translations.Add(translationEntity); await SaveChangesAsync(); } return(new Tuple <BookWord, Translation>(bookWordEntity, translationEntity)); }