public async Task <bool> EditWord(WordTranslationEditModel model) { using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { bool updateBase = await wordService.UpdateAsync(new WordModel { Id = model.Id, Description = model.Description, Transcription = model.Transcription, PartOfSpeechId = model.PartOfSpeechId, Comment = model.Comment }); bool translationsRemoved = true; if (model.TranslationsToDeleteIdRange != null && model.TranslationsToDeleteIdRange.Count > 0) { translationsRemoved = await wordTranslationService.RemoveIdRangeAsync(model.Id, model.TranslationsToDeleteIdRange); } if (model.TranslationsToAddRange != null && model.TranslationsToAddRange.Count > 0) { List <int> translationIds = await CreateNonExistingWords(model.TranslationsToAddRange, model.TranslationLanguageId); await wordTranslationService.AddIdRangeAsync(model.Id, translationIds, model.OwnerId); } if (model.SynonymsToAddIdRange != null && model.SynonymsToAddIdRange.Count > 0) { List <int> synonymIds = await CreateNonExistingWords(model.SynonymsToAddIdRange, model.OriginalLanguageId); await wordTranslationService.AddIdRangeAsync(model.Id, synonymIds, model.OwnerId); } bool synonymsRemoved = true; if (model.SynonymsToDeleteIdRange != null && model.SynonymsToDeleteIdRange.Count > 0) { synonymsRemoved = await wordTranslationService.RemoveIdRangeAsync(model.Id, model.SynonymsToDeleteIdRange); } if (model.TagsToAddRange != null && model.TagsToAddRange.Count > 0) { List <int> tagIds = await CreateNonExistingTags(model.TagsToAddRange); await tagService.AddRangeToWordAsync(model.Id, tagIds); } bool tagsRemoved = true; if (model.TagsToDeleteIdRange != null && model.TagsToDeleteIdRange.Count > 0) { tagsRemoved = await tagService.RemoveIdRangeAsync(model.Id, model.TagsToDeleteIdRange); } if (updateBase && translationsRemoved && synonymsRemoved && tagsRemoved) { transaction.Complete(); return(true); } return(false); } }