コード例 #1
0
ファイル: PostRepository.cs プロジェクト: unsinedZ/Imagegram
        private ProjectionModels.Comment MapEntitiesIntoProjection(EntityModels.Comment comment, EntityModels.Account account)
        {
            var projection = mapper.Map <ProjectionModels.Comment>(comment);

            projection.Creator = mapper.Map <ProjectionModels.Account>(account);
            return(projection);
        }
コード例 #2
0
ファイル: CommentService.cs プロジェクト: unsinedZ/Imagegram
        public async Task <ProjectionModels.Comment> CreateAsync(EntityModels.Comment comment)
        {
            if (comment is null)
            {
                throw new ArgumentNullException(nameof(comment));
            }

            await ValidatePostIdAsync(comment.PostId);

            var createdId = await commentRepository.CreateAsync(comment);

            return(await commentRepository.GetAsync(createdId));
        }
コード例 #3
0
        public async Task <Guid> CreateAsync(EntityModels.Comment comment)
        {
            comment.Id        = Guid.NewGuid();
            comment.CreatedAt = currentUtcDateProvider.UtcNow;
            using (var connection = OpenConnection())
            {
                using (var transaction = connection.BeginTransaction())
                {
                    await connection.InsertAsync(comment, transaction);

                    await connection.ExecuteAsync(@"
                        update [dbo].[Posts]
                        set [CommentsCount] = [CommentsCount] + 1
                        where [Id] = @postId",
                                                  new { postId = comment.PostId },
                                                  transaction);

                    transaction.Commit();
                }

                return(comment.Id);
            }
        }