public async Task<int> AddWord(WordModel model) { using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { int origWordId = await wordService.AddAsync(model); if (model.Translations != null && model.Translations.Count > 0) { List<int> translationIds = await CreateNonExistingWords(model.Translations, model.TranslationLanguageId); await wordTranslationService.AddIdRangeAsync(origWordId, translationIds, model.OwnerId); } if (model.Synonyms != null && model.Synonyms.Count > 0) { List<int> synonymIds = await CreateNonExistingWords(model.Synonyms, model.LanguageId); await wordTranslationService.AddIdRangeAsync(origWordId, synonymIds, model.OwnerId); } if (model.Tags != null && model.Tags.Count > 0) { List<int> tagIds = await CreateNonExistingTags(model.Tags); await tagService.AddRangeToWordAsync(origWordId, tagIds); } transaction.Complete(); return origWordId; } }
public async Task<IHttpActionResult> Post(WordModel word) { if (await _wordManagService.AddWord(word) > 0) { return Ok(); } return BadRequest("Failed to add Word."); }
public Word ToDomainModel(WordModel apiModel) { return(new Word() { Id = apiModel.Id, LanguageId = apiModel.LanguageId, Value = apiModel.Value, Transcription = apiModel.Transcription, Description = apiModel.Description }); }
public Word ToDomainModel(WordModel apiModel) { return new Word() { Id = apiModel.Id, LanguageId = apiModel.LanguageId, Value = apiModel.Value, Transcription = apiModel.Transcription, Description = apiModel.Description }; }
public Word ToDomainModel(WordModel apiModel) { return(new Word() { Id = apiModel.Id, LanguageId = apiModel.LanguageId, Value = apiModel.Value, Transcription = apiModel.Transcription, Description = apiModel.Description, PartOfSpeechId = apiModel.PartOfSpeechId, Comment = apiModel.Comment }); }
public int Post(WordModel word) { if (word == null) throw new System.ArgumentNullException("empty word model"); return _service.Add(_mapper.ToDomainModel(word)); }
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 Add(WordModel word) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { int existResult = Exists(word.Value, word.LanguageId); if (existResult > 0) { return -1; } var wordToAdd = wordMapper.ToDomainModel(word); uow.WordRepository.Add(wordToAdd); uow.Save(); return wordToAdd.Id; } }
public async Task<bool> UpdateAsync(WordModel word) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var oldWord = uow.WordRepository.GetById(word.Id); oldWord.Description = word.Description; oldWord.Transcription = word.Transcription; uow.WordRepository.Update(oldWord); await uow.SaveAsync(); } return true; }
private async Task<List<int>> CreateNonExistingWords(List<WordValueModel> words, int languageId) { List<int> translationIds = new List<int>(); foreach (var translation in words) { if (translation.Id == null) { WordModel wordToAdd = new WordModel { Value = translation.Value, LanguageId = languageId }; translation.Id = await wordService.AddAsync(wordToAdd); } translationIds.Add(translation.Id ?? default(int)); } return translationIds; }