Ejemplo n.º 1
0
 public async Task <IHttpActionResult> Post(WordModel word)
 {
     if (await _wordManagService.AddWord(word) > 0)
     {
         return(Ok());
     }
     return(BadRequest("Failed to add Word."));
 }
        public async Task <List <WordTranslationModel> > Post(List <WordTranslationImportModel> wordTranslations)
        {
            List <WordTranslationModel> wordTranslationsToReturn = new List <WordTranslationModel>();

            foreach (WordTranslationImportModel wordTranslation in wordTranslations)
            {
                wordTranslation.OriginalWordId = await wordService.ExistsAsync(wordTranslation.OriginalWord, wordTranslation.LanguageId);

                if (wordTranslation.OriginalWordId == 0)
                {
                    WordModel modelForAdd = new WordModel()
                    {
                        Value          = wordTranslation.OriginalWord,
                        LanguageId     = wordTranslation.LanguageId,
                        Transcription  = wordTranslation.Transcription,
                        Description    = wordTranslation.Description,
                        Comment        = wordTranslation.Comment,
                        PartOfSpeechId = wordTranslation.PartOfSpeechId
                    };
                    foreach (var i in wordTranslation.Tags)
                    {
                        modelForAdd.Tags.Add(new TagModel()
                        {
                            Id    = null,
                            Value = i.Value
                        });
                    }
                    wordTranslation.OriginalWordId = await editService.AddWord(modelForAdd);
                }

                wordTranslation.TranslationWordId = await wordService.ExistsAsync(wordTranslation.TranslationWord, TranslationLanguageId);

                if (wordTranslation.TranslationWordId == 0)
                {
                    wordTranslation.TranslationWordId = await wordService.AddAsync(new WordModel()
                    {
                        Value      = wordTranslation.TranslationWord,
                        LanguageId = TranslationLanguageId
                    });
                }

                wordTranslation.OwnerId = UserId;
                int wordTranslationId = wordTranslationService.Add(wordTranslationMapper.Map(wordTranslation));

                wordTranslationsToReturn.Add(new WordTranslationModel()
                {
                    Id              = wordTranslationId,
                    OriginalWord    = wordTranslation.OriginalWord,
                    TranslationWord = wordTranslation.TranslationWord
                });
            }

            return(wordTranslationsToReturn);
        }