public List <WordTranslationModel> Post(List <WordTranslationImportModel> wordTranslations) { List <WordTranslationModel> wordTranslationsToReturn = new List <WordTranslationModel>(); foreach (WordTranslationImportModel wordTranslation in wordTranslations) { wordTranslation.OriginalWordId = wordService.Exists(wordTranslation.OriginalWord, wordTranslation.LanguageId); if (wordTranslation.OriginalWordId == 0) { wordTranslation.OriginalWordId = wordService.Add(wordMapper.ToDomainModel(new WordModel() { Value = wordTranslation.OriginalWord, LanguageId = wordTranslation.LanguageId, Transcription = wordTranslation.Transcription, Description = wordTranslation.Description })); } wordTranslation.TranslationWordId = wordService.Exists(wordTranslation.TranslationWord, TranslationLanguageId); if (wordTranslation.TranslationWordId == 0) { wordTranslation.TranslationWordId = wordService.Add(wordMapper.ToDomainModel(new WordModel() { Value = wordTranslation.TranslationWord, LanguageId = TranslationLanguageId })); } foreach (TagModel tag in wordTranslation.Tags) { tag.Id = tagService.Exists(tag.Name); if (tag.Id == 0) { tag.Id = tagService.Add(tagMapper.Map(tag)); } } wordTranslation.OwnerId = UserId; int wordTranslationId = wordTranslationService.Add(wordTranslationMapper.Map(wordTranslation, tagMapper.MapRange(wordTranslation.Tags))); wordTranslationsToReturn.Add(new WordTranslationModel() { Id = wordTranslationId, OriginalWord = wordTranslation.OriginalWord, TranslationWord = wordTranslation.TranslationWord }); } return(wordTranslationsToReturn); }
public async Task <int> AddAsync(WordModel word) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { int existResult = await ExistsAsync(word.Value, word.LanguageId); if (existResult > 0) { return(-1); } var wordToAdd = wordMapper.ToDomainModel(word); uow.WordRepository.Add(wordToAdd); await uow.SaveAsync(); return(wordToAdd.Id); } }
public int Post(WordModel word) { if (word == null) { throw new System.ArgumentNullException("empty word model"); } return(_service.Add(_mapper.ToDomainModel(word))); }