예제 #1
0
        public Task <int> Write(Comment comment)
        {
            var errors = _validator.Validate(comment).ToArray();

            if (errors.Any())
            {
                throw new ValidationException(errors);
            }

            return(_writer.Write(comment));
        }
예제 #2
0
        public async Task <IActionResult> Create(string topic, Comment comment)
        {
            comment.Topic = topic;
            comment.User  = _userLocator.Find(this.Request);
            int id;

            try
            {
                id = await _writer.Write(comment);
            }
            catch (ValidationException e)
            {
                return(BadRequest(e.Message));
            }

            return(CreatedAtRoute("GetComment", new { id, topic }, comment));
        }