コード例 #1
0
        public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            if (request.TopicPost == null || request.TopicPost.TopicId == 0 || request.TopicPost.PostId == 0)
            {
                throw new BusinessException("AddWrongInformation");
            }

            var checkPost = (await topicPostQueries.Gets($"topic_id = {request.TopicPost.TopicId} and post_id = {request.TopicPost.PostId}")).FirstOrDefault();

            if (checkPost != null)
            {
                throw new BusinessException("Post.NotExisted");
            }

            return(await topicPostRepository.Add(request.TopicPost) > 0 ? 0 : throw new BusinessException("Common.AddFail"));
        }
コード例 #2
0
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.TopicPost == null || request.TopicPost.Id == 0 || request.TopicPost.PostId == 0)
            {
                throw new BusinessException("AddWrongInformation");
            }

            var topicPost = (await topicPostQueries.Gets($"id = {request.TopicPost.Id}")).FirstOrDefault();

            if (topicPost != null)
            {
                topicPost.PostId = request.TopicPost.PostId;
                var rs = await topicPostRepository.Update(topicPost);

                return(rs == 0 ? 0 : throw new BusinessException("Common.UpdateFail"));
            }

            return(0);
        }