Exemple #1
0
        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);
        }
Exemple #2
0
        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));
        }
        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);
            }
        }