public HttpResponseMessage Post(Comment comment) { if (!User.Identity.IsAuthenticated) { return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Please log in."); } comment.UpdatedAt = DateTime.Now; comment.Id = _commentService.Save(comment); return Request.CreateResponse(HttpStatusCode.OK, comment); }
public long Save(Comment comment) { using (IDbConnection connection = OpenConnection()) { const string query = "INSERT INTO Comments(UserId, Message, EventId, UpdatedAt)" + "VALUES (@UserId, @Message, @EventId, @UpdatedAt)"; var rowsAffected = connection.Execute(query, new { UserId = comment.User.Id, comment.Message, comment.EventId, UpdatedAt = comment.UpdatedAt }); return rowsAffected; } }
public long Save(Comment comment) { return _commentRepository.Save(comment); }