Esempio n. 1
0
        private async void LikeDislikeButton_Click(object sender, RoutedEventArgs e)
        {
            int       likeDislike = int.Parse(((Button)sender).Tag.ToString());
            LikeVideo request     = new LikeVideo()
            {
                LikeDislike = likeDislike, UserID = SettingsManager.Username, VideoID = video.VideoID
            };
            Object response = await ConnectionManager.SendRequestAsync(request, RequestType.LikeVideo, ResponseType.Acknowledge);

            if (response != null)
            {
                if (((JObject)response).ToObject <Acknowledge>().Status == "OK")
                {
                    int likes    = int.Parse(likeTextBlock.Text);
                    int dislikes = int.Parse(dislikeTextBlock.Text);
                    if (likeDislike > 0)
                    {
                        likeTextBlock.Text   = (likes + 1).ToString();
                        likeDislikeBar.Value = (likes + 1) * 100 / (likes + dislikes + 1);
                    }
                    else
                    {
                        dislikeTextBlock.Text = (dislikes + 1).ToString();
                        likeDislikeBar.Value  = (likes) * 100 / (likes + dislikes + 1);
                    }
                }
            }
        }
Esempio n. 2
0
        private static Response LikeVideoResponse(LikeVideo likeVideo)
        {
            DatabaseManager database = new DatabaseManager();
            string          query    = "";

            if (likeVideo.LikeDislike > 0)
            {
                query = $"UPDATE video_details SET likes=likes+1 WHERE videoid = '{likeVideo.VideoID}'";
            }
            else
            {
                query = $"UPDATE video_details SET dislikes=dislikes+1 WHERE videoid = '{likeVideo.VideoID}'";
            }
            (MySqlDataReader reader, var Connection) = database.RunQuery(query);
            Acknowledge ack = new Acknowledge()
            {
                Status = "OK", Reason = "Liked"
            };
            Response resp = new Response()
            {
                Type = ResponseType.Acknowledge, Status = "OK", Content = ack
            };

            if (reader == null)
            {
                ack.Reason = "Unable to like";
                ack.Status = "FAIL";
            }
            Connection.Close();
            return(resp);
        }