public IHttpActionResult AddComment(Comment comment) { if ((comment.Username?.Length ?? 0) == 0) { return(BadRequest("A username is required.")); } else if (comment.Username.Length > UsernameMaxLength) { return(BadRequest(string.Format("A username must not exceed {0} characters.", UsernameMaxLength))); } else if ((comment.Content?.Length ?? 0) == 0) { return(BadRequest("A comment is required.")); } else if (comment.Content.Length > ContentMaxLength) { return(BadRequest(string.Format("A comment must not exceed {0} characters.", ContentMaxLength))); } _repository.Comments.Add(comment); _repository.SaveChanges(); _webSocketHub.Broadcast(JsonConvert.SerializeObject(comment)); return(StatusCode(HttpStatusCode.OK)); }
public override void OnMessage(string message) { _hub.Broadcast(message); }