Пример #1
0
        public async Task <EntityDto <Guid> > CreateTextComment(CreateTextCommentInput input)
        {
            var currentUser = await GetCurrentUserAsync();

            Comment textComment = null;

            if (input.ActivityId.HasValue)
            {
                var activity = await _activityManager.GetAsync(input.ActivityId.Value);

                textComment = await _commentManager.CreateAsync(TextComment.Create(input.Content, activity, currentUser));
            }
            else if (input.ActivityTemplateId.HasValue)
            {
                var activityTemplate = await _activityTemplateManager.GetAsync(input.ActivityTemplateId.Value);

                textComment = await _commentManager.CreateAsync(TextComment.Create(input.Content, activityTemplate, currentUser));
            }
            else if (input.ActivityPlanId.HasValue)
            {
                var activityPlan = await _activityPlanManager.GetAsync(input.ActivityPlanId.Value);

                textComment = await _commentManager.CreateAsync(TextComment.Create(input.Content, activityPlan, currentUser));
            }
            else
            {
                throw new UserFriendlyException("Please provide either abstractActivityId or activityPlanId.");
            }

            return(new EntityDto <Guid>(textComment.Id));
        }
Пример #2
0
        protected virtual async Task <CommentEditDto> Create(CommentEditDto input)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            var entity = ObjectMapper.Map <Comment>(input);

            entity.Id = SequentialGuidGenerator.Instance.Create();

            //调用领域服务
            entity = await _commentManager.CreateAsync(entity);

            var dto = ObjectMapper.Map <CommentEditDto>(entity);

            return(dto);
        }
        /// <inheritdoc/>
        public async Task AddAsync()
        {
            _logger.LogInformation(SyncMessage.CommentAddStart);

            var commentsCloud = await _cloudManager.GetComments().ToListAsync();

            var commentsApp = (await _commentManager.GetAllAsync()).ToList();
            var postsApp    = (await _postManager.GetAllAsync()).ToList();

            var commentCloudIds = commentsCloud.Select(c => c.Id);
            var commentAppIds   = commentsApp.Select(c => c.CloudId);

            var newIds   = commentCloudIds.Except(commentAppIds);
            var comments = commentsCloud.Join(
                newIds,
                commentCloud => commentCloud.Id,
                id => id,
                (commentCloud, id) => commentCloud);

            if (comments.Any())
            {
                foreach (var comment in comments)
                {
                    var post = postsApp.FirstOrDefault(p => p.CloudId == comment.PostId);

                    if (post != null)
                    {
                        var commentDto = new CommentDto
                        {
                            CloudId = comment.Id,
                            PostId  = post.Id,
                            Name    = comment.Name,
                            Email   = comment.Email,
                            Body    = comment.Body
                        };

                        await _commentManager.CreateAsync(commentDto);
                    }
                    else
                    {
                        _logger.LogError(SyncMessage.CommentAddError, comment.PostId);
                    }
                }
            }

            _logger.LogInformation(SyncMessage.CommentAddEnd);
        }
Пример #4
0
 public void Method_Throws_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => _commentManager.CreateAsync(null).GetAwaiter().GetResult());
     Assert.Throws <ArgumentNullException>(() => _commentManager.UpdateAsync(null).GetAwaiter().GetResult());
 }