Ejemplo n.º 1
0
 public BookWordDto(BookWord bookWord)
 {
     this.id = bookWord.Id;
     this.book = bookWord.BookId;
     this.word = bookWord.WordId;
     this.speachPart = bookWord.SpeachPart;
 }
Ejemplo n.º 2
0
 public BookWordDto(BookWord bookWord)
 {
     this.id         = bookWord.Id;
     this.book       = bookWord.BookId;
     this.word       = bookWord.WordId;
     this.speachPart = bookWord.SpeachPart;
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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));
        }