public Task <int> Write(Comment comment) { var errors = _validator.Validate(comment).ToArray(); if (errors.Any()) { throw new ValidationException(errors); } return(_writer.Write(comment)); }
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)); }