public async Task <IResultModel> Add(TopicAddModel model) { var entity = _mapper.Map <TopicEntity>(model); //if (await _repository.Exists(entity)) //{ //return ResultModel.HasExists; //} using var uow = _forumDbContext.NewUnitOfWork(); var result = await _repository.AddAsync(entity, uow); if (result && model.Tags != null && model.Tags.Count() > 0) { var tagList = model.Tags.Select(s => new TopicTagEntity { TopicId = entity.Id, TagId = s }).ToList(); //新增只需要重新添加即可 消息队列处理 await _topicTagRepository.AddAsync(tagList, uow); uow.Commit(); if (model.Tags.Count() > 0) { await _tagRepository.AddCount(model.Tags, true); } await _categoryRepository.AddCount(new int[] { entity.CategoryId }, true); } return(ResultModel.Result(result)); }