Last active
August 19, 2019 18:31
-
-
Save Taifunov/fc1603d8fd85f2e2ba4e840bc11c30bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static PostData UpdatePostData(SQLiteConnection conn, int messageId, bool isLiked) | |
{ | |
PostData postData; | |
if (isLiked) | |
{ | |
var likesCount = conn.ExecuteReader("SELECT (Likes) FROM PostData AS pd WHERE pd.MessageId = @MessageId", new { messageId }).Parse<int>().FirstOrDefault(); | |
var temp = 1; | |
if (likesCount > 0) | |
{ | |
temp = likesCount++; | |
} | |
using (SQLiteCommand cmd = new SQLiteCommand($"UPDATE PostData SET Likes = '{likesCount}' WHERE MessageId = '{messageId}'", conn)) | |
{ | |
cmd.ExecuteNonQuery(); | |
} | |
} | |
else | |
{ | |
var disLikesCount = conn.ExecuteReader("SELECT (DisLikes) FROM PostData AS pd WHERE pd.MessageId = @MessageId", new { messageId }).Parse<int>().FirstOrDefault(); | |
var temp = 1; | |
if (disLikesCount > 0) | |
{ | |
temp = disLikesCount++; | |
} | |
using (SQLiteCommand cmd = new SQLiteCommand($"UPDATE PostData SET DisLikes = '{disLikesCount}' WHERE MessageId = '{messageId}'", conn)) | |
{ | |
cmd.ExecuteNonQuery(); | |
} | |
} | |
postData = conn.ExecuteReader("SELECT * FROM PostData AS pd WHERE pd.MessageId = @MessageId", new { messageId }).Parse<PostData>().FirstOrDefault(); | |
return postData; | |
} | |
postData = UpdatePostData(conn, e.CallbackQuery.Message.MessageId, true); | |
await _bot.EditMessageReplyMarkupAsync( | |
channelId, | |
e.CallbackQuery.Message.MessageId, | |
new InlineKeyboardMarkup(new[] | |
{ | |
new [] { | |
new InlineKeyboardButton{Text = $"👍 {postData.Likes}" , CallbackData = "post_id like"}, | |
new InlineKeyboardButton{Text = $"👎 {postData.DisLikes}",CallbackData = "post_id dislike"}, }, | |
}), | |
default); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment