Exemplo n.º 1
0
        public async Task <ActionResult> CreateAsync([FromBody] PostCreateInfo createInfo, CancellationToken token)
        {
            try
            {
                var post = await this.postsService.CreatePostAsync(createInfo, token);

                return(this.Ok(post));
            }
            catch (ValidationException ex)
            {
                return(this.BadRequest(ex.ValidationResult));
            }
        }
Exemplo n.º 2
0
        public async Task <Post> CreatePostAsync(PostCreateInfo createInfo, CancellationToken token)
        {
            var utcNow = DateTime.UtcNow;
            var post   = new Post
            {
                Id        = Guid.NewGuid().ToString(),
                Title     = createInfo.Title,
                Text      = createInfo.Text,
                Tags      = createInfo.Tags,
                CreatedAt = createInfo.CreatedAt?.ToUniversalTime() ?? utcNow,
            };

            await this.postsCollection.InsertOneAsync(post, cancellationToken : token);

            return(post);
        }