/// <summary> /// 取消对评论的不赞同 /// </summary> /// <param name="Qusitionid"></param> /// <param name="Userid"></param> /// <param name="CmdUserid"></param> /// <param name="CmtedUserid"></param> /// <returns></returns> public bool DelPutDisLike(CommentPlus commentPlus) { SqlConnection sqlConnection = new SqlConnection(connectionstring); sqlConnection.Open(); using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { SqlTransaction sqlTransaction = sqlConnection.BeginTransaction(); try { string sql = "update CommentTable set DownCmtnum=DownCmtnum-1 where Qusitonid=@Qusitionid and Userid=@Userid and CmtUserid=@CmtUserid and CmtedUserid=@CmtedUserid and CmtTime=@datetime"; sqlCommand.CommandText = sql; sqlCommand.Parameters.AddWithValue("@Qusitionid", commentPlus.Qusitionid); sqlCommand.Parameters.AddWithValue("@Userid", commentPlus.Userid); sqlCommand.Parameters.AddWithValue("@CmtUserid", commentPlus.CmtedUserid); sqlCommand.Parameters.AddWithValue("@CmtedUserid", commentPlus.CmtedUserid); sqlCommand.Parameters.AddWithValue("@datetime", commentPlus.Datetime); sqlCommand.Transaction = sqlTransaction; sqlCommand.ExecuteNonQuery(); sqlTransaction.Commit(); return(true); } catch (SqlException) { sqlTransaction.Rollback(); return(false); } finally { sqlConnection.Close(); } } }
/// <summary> /// 得到listviewitem中的子空间 /// </summary> /// <param name="listViewItem"></param> /// <returns></returns> private CommentPlus GetCmtInfor(ListViewItem listViewItem) { int CmtedUserid, CmdUserid; string dateTime; TextBlock CmtUseridBlock = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("CmtUseridBlock") as TextBlock; CmdUserid = Convert.ToInt32(CmtUseridBlock.Text); TextBlock CmtedUseridBlock = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("CmtedUseridBlock") as TextBlock; CmtedUserid = Convert.ToInt32(CmtedUseridBlock.Text); var CmtTime = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("CmtTime") as TextBlock; dateTime = (CmtTime.Text); CommentPlus comment = new CommentPlus { Qusitionid = Qusitionid, Userid = Userid, CmdUserid = CmdUserid, CmtedUserid = CmtedUserid, Datetime = dateTime, Myid = Myid }; return(comment); }
private async void CAcceptButton_Click(object sender, RoutedEventArgs e) { AppBarButton appBarButton = (AppBarButton)sender; ListViewItem listViewItem = FindParent <ListViewItem>(appBarButton); CommentPlus commentp = GetCmtInfor(listViewItem); var box = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("Commentadd") as TextBox; var CmdName = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("CmdName") as Button; var CmdsName = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("CmtUseridNameBlock") as TextBlock; var cmtedName = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("CmtedName") as Button; string Text = box.Text; Comment comment = new Comment { Qusitionid = Comments.Qusitionid, Userid = Comments.Userid, CmtContent = Text, CmdUserid = Myid, CmtedUserid = Comments.CmtedUserid, CmtTime = DateTime.Now, CmtedUseridName = CmdName.Content.ToString(), CmdUseridName = people.Name, UseridName = CmdsName.Text, }; await PostComment(comment); if ((listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("AddCmdGrid") is Grid AddCmdGrid) { AddCmdGrid.Visibility = Visibility.Collapsed; } }
/// <summary> /// 赞同按钮被点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void LikeButton_Click(object sender, RoutedEventArgs e) { AppBarButton appBarButton = (AppBarButton)sender; ListViewItem listViewItem = FindParent <ListViewItem>(appBarButton); CommentPlus commentPlus = GetCmtInfor(listViewItem); var fore = appBarButton.Foreground as SolidColorBrush; if (fore.Color == Colors.Blue) { await DelPutCmdLike(commentPlus, listViewItem); } else { await PutCmdLike(commentPlus, listViewItem); } }
private async Task DelPutCmdDislike(CommentPlus commentPlus, ListViewItem listViewItem) { int Myid = (HomePage.Current.myStruct.id); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent(JsonConvert.SerializeObject(commentPlus), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = await httpClient.PutAsync($"http://localhost:60671/api/comment/delputdislike", content); var res = await httpResponseMessage.Content.ReadAsAsync <bool>(); if (res == true) { Modifyinf(listViewItem, 1, commentPlus); } }
/// <summary> /// 修改按钮的颜色 /// </summary> /// <param name="listViewItem"></param> /// <param name="option"></param> /// <param name="CmdUserid"></param> /// <param name="CmtedUserid"></param> private void Modifyinf(ListViewItem listViewItem, int option, CommentPlus commentP) { var comment = commentPlus.Where(p => p.CmdUserid == commentP.CmdUserid && p.CmtedUserid == commentP.CmtedUserid).FirstOrDefault(); if (listViewItem != null) { AppBarButton LikeButton = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("LikeButton") as AppBarButton; AppBarButton DisLikeButton = (listViewItem.ContentTemplateRoot as FrameworkElement)?.FindName("DislikeButton") as AppBarButton; ///点击like按钮,根据颜色来判断 if (option == 0) { var fore = LikeButton.Foreground as SolidColorBrush; if (fore.Color == Colors.Black) { comment.UpCmtnum++; LikeButton.Foreground = new SolidColorBrush(Colors.Blue); NameMap.UPAnswerCmt.Add($"{commentP.Qusitionid} {commentP.Userid} {commentP.Datetime} {Myid} {commentP.CmdUserid} {commentP.CmtedUserid}"); } else if (fore.Color == Colors.Blue) { comment.UpCmtnum--; LikeButton.Foreground = new SolidColorBrush(Colors.Black); NameMap.UPAnswerCmt.Remove($"{commentP.Qusitionid} {commentP.Userid} {commentP.Datetime} {Myid} {commentP.CmdUserid} {commentP.CmtedUserid}"); } LikeButton.Label = (comment.UpCmtnum).ToString(); } else///点击dislike按钮,根据颜色来判断 { var fore = DisLikeButton.Foreground as SolidColorBrush; if (fore.Color == Colors.Black) { comment.DownCmtnum++; DisLikeButton.Foreground = new SolidColorBrush(Colors.Blue); NameMap.DNAnswerCmt.Add($"{commentP.Qusitionid} {commentP.Userid} {commentP.Datetime} {Myid} {commentP.CmdUserid} {commentP.CmtedUserid}"); } else if (fore.Color == Colors.Blue) { comment.DownCmtnum--; DisLikeButton.Foreground = new SolidColorBrush(Colors.Black); NameMap.DNAnswerCmt.Remove($"{commentP.Qusitionid} {commentP.Userid} {commentP.Datetime} {Myid} {commentP.CmdUserid} {commentP.CmtedUserid}"); } DisLikeButton.Label = (comment.DownCmtnum).ToString(); } } }
public bool DelPutdislike([FromBody] CommentPlus commentPlus) { CommentAccess commentAccess = new CommentAccess(); return(commentAccess.DelPutDisLike(commentPlus)); }
public bool PutLike([FromBody] CommentPlus commentPlus) { CommentAccess comment = new CommentAccess(); return(comment.PutLike(commentPlus)); }