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();

                await _tagRepository.AddCount(model.Tags);

                await _categoryRepository.AddCount(new int[] { entity.CategoryId });
            }
            return(ResultModel.Result(result));
        }
Пример #2
0
        public async Task <IResultModel> Add(TopicTagAddModel model)
        {
            var entity = _mapper.Map <TopicTagEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }