Exemple #1
0
        public async Task CreatePostAsync(SavePostModel savePostModel)
        {
            ArgumentGuard.NotNull(savePostModel, nameof(savePostModel));

            await _validatorfactory.ValidateAsync(savePostModel);

            var post = new PostEntity
            {
                Id      = Guid.NewGuid(),
                Title   = savePostModel.Title,
                Content = savePostModel.Content,
                Status  = PostStatus.Draft,
                Tags    = savePostModel.Tags.Select(t => new TagEntity {
                    Id = Guid.NewGuid(), Name = t
                }).ToList(),
                CreatedDateUtc = DateTime.UtcNow,
                AuthorId       = _userContext.UserId
            };

            await _postRepository.AddAsync(post);
        }
Exemple #2
0
        public async Task <Guid> AddCommentAsync(Guid postId, SaveCommentModel model)
        {
            ArgumentGuard.NotEmpty(postId, nameof(postId));
            ArgumentGuard.NotNull(model, nameof(model));

            await _validatorFactory.ValidateAsync(model);

            var commentEntity = new CommentEntity
            {
                Id              = Guid.NewGuid(),
                Content         = model.Content,
                AuthorId        = _userContext.UserId,
                PostId          = postId,
                CreatedDateUtc  = DateTime.UtcNow,
                LastModfiedById = _userContext.UserId,
            };

            return(await _commentRepository.AddAsync(commentEntity));
        }