Esempio n. 1
0
        public async Task <TopicResponse> SaveAsync(Topic Topic)
        {
            try
            {
                await _topicRepository.AddAsync(Topic);

                await _unitOfWork.CompleteAsync();

                return(new TopicResponse(Topic));
            }
            catch (Exception e)
            {
                return(new TopicResponse("Has ocurred an error saving the Topic" + e.Message));
            }
        }
        public async Task <ApiRequestResult> AddAsync(TopicDto dto)
        {
            var command = dto.EntityMap <TopicDto, Topic>();
            await _topicRepository.AddAsync(command);

            return(ApiRequestResult.Success("添加成功"));
        }
Esempio n. 3
0
        public async Task CreateTopic(Topic topic, bool dryRun)
        {
            var existingTopics = await _topicRepository.GetAllAsync();

            var existingClusters = await _clusterRepository.GetAllAsync();

            if (existingTopics.Any(t =>
            {
                return(t.Name.Equals(topic.Name) && t.KafkaClusterId.Equals(topic.KafkaClusterId));
            }))
            {
                throw new TopicAlreadyExistException(topic.Name);
            }

            if (!existingClusters.Any(c => c.Id.Equals(topic.KafkaClusterId)))
            {
                throw new ClusterDoesNotExistException(topic.KafkaClusterId.ToString());
            }

            if (!existingClusters.First(c => c.Id.Equals(topic.KafkaClusterId)).Enabled)
            {
                throw new ClusterIsDisabledException();
            }

            if (dryRun)
            {
                return;
            }

            await _topicRepository.AddAsync(topic);
        }
        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));
        }
Esempio n. 5
0
        public async Task <int> AddTopicAsync(Topic topic)
        {
            await Locker.WaitAsync();

            try
            {
                if (Exists(topic))
                {
                    return(-1);
                }

                var notifyevent = new NotifyEvent <Topic>
                {
                    Object      = topic,
                    Description = "NewTopic",
                    Date        = DateTime.Now,
                };

                var result = await _repository.AddAsync(topic);

                if (result != -1)
                {
                    _notifier.SendMessage(notifyevent);
                }

                return(result);
            }
            finally
            {
                Locker.Release();
            }
        }
Esempio n. 6
0
        public async Task Integration()
        {
            if ((await _topicRepository.GetAllAsync()).Any())
            {
                return;
            }

            List <Topic> topics = await GetTopics();

            foreach (Topic topic in topics)
            {
                await _topicRepository.AddAsync(topic);
            }

            await _topicRepository.CommitAsync();
        }
        public async Task CreateTopic(Topic topic, bool dryRun)
        {
            var existingTopics = await _topicRepository.GetAllAsync();

            if (existingTopics.Any(t => t.Name.Equals(topic.Name)))
            {
                throw new TopicAlreadyExistException(topic.Name);
            }

            if (dryRun)
            {
                return;
            }

            await _topicRepository.AddAsync(topic);
        }
        public async Task <int> Handle(CreateTopicCommand request, CancellationToken cancellationToken)
        {
            Topic topic = new Topic(
                request.Title,
                request.Description,
                request.StartDate.Value,
                request.EndDate.Value,
                request.Map,
                request.RegionId.Value,
                request.EraId.Value);

            await _topicRepository.AddAsync(topic);

            await _topicRepository.UnitOfWork.SaveEntitiesAsync();

            return(topic.Id);
        }