public HttpResponseMessage Post(Hate item)
 {
     item = repository.Save(item);
     return Request.CreateResponse(HttpStatusCode.Created, item);
 }
        public Hate Save(Hate item)
        {
            item.Created = DateTime.Now;
            using (var conn = Connection)
            {
                conn.Open();

                var transaction = conn.BeginTransaction();

                var command = new MySqlCommand("INSERT INTO hate (created, network, networkId, author, text, token) VALUES (@Created, @Network, @NetworkId, @Author, @Text, @Token);", conn, transaction);

                command.Parameters.AddWithValue("@Created", item.Created);
                command.Parameters.AddWithValue("@Network", item.Network);
                command.Parameters.AddWithValue("@NetworkId", item.NetworkId);
                command.Parameters.AddWithValue("@Author", item.Author);
                command.Parameters.AddWithValue("@Text", item.Text);
                command.Parameters.AddWithValue("@Token", item.Token);
                command.ExecuteNonQuery();

                var idCommand = new MySqlCommand("SELECT LAST_INSERT_ID();", conn, transaction);
                var id = idCommand.ExecuteScalar();
                item.Id = Convert.ToInt32(id);

                foreach (var category in item.Categories)
                {
                    var categoryCommand = new MySqlCommand("INSERT INTO `hate-categories` (hateId, category) VALUES (@HateId, @Category);", conn, transaction);
                    categoryCommand.Parameters.AddWithValue("@HateId", item.Id);
                    categoryCommand.Parameters.AddWithValue("@Category", category);
                    categoryCommand.ExecuteNonQuery();
                }

                transaction.Commit();
            }
            return item;
        }