public bool SetLike(Guid postId, Guid accountId)
{
string queryString =
"INSERT INTO [dbo].Likes ([dbo].Likes.likeid, [dbo].Likes.postid, [dbo].Likes.accountid) " +
"VALUES (@likeid, @postid, @accountid); " +
"UPDATE [dbo].[posts] " +
"SET [rating] = rating + 1 " +
"WHERE [dbo].posts.postid = @postid";
using (SqlConnection connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("likeid", Guid.NewGuid());
command.Parameters.AddWithValue("postid", postId);
command.Parameters.AddWithValue("accountid", accountId);
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception) { return false; throw new Exception(); }
}
return true;
}