예제 #1
0
 protected void btnLike_Click(object sender, ImageClickEventArgs e)
 {
     if (Session["loginuser"] == null)
     {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "Poppp", "openLogin();", true);
     }
     else
     {
         var    x     = sender as ImageButton;
         string UID   = Session["loginuser"].ToString();
         string PID   = x.Attributes["imgId"];
         string liked = x.ImageUrl;
         int    likes = Convert.ToInt32(lblLikeCount.Text);
         if (liked == "/Images/unlike.png")
         {
             if (LikeClass.sendLike(UID, PID) == true)
             {
                 x.ImageUrl = "/Images/like.png";
                 likes     += 1;
             }
         }
         else if (liked == "/Images/like.png")
         {
             if (LikeClass.UnLike(UID, PID) == true)
             {
                 x.ImageUrl = "/Images/unlike.png";
                 likes     -= 1;
             }
         }
         lblLikeCount.Text = likes.ToString();
     }
 }
예제 #2
0
 protected void btnLike_Click(object sender, ImageClickEventArgs e)
 {
     if (Session["loginuser"] == null)
     {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
     }
     else
     {
         var    x     = sender as ImageButton;
         string UID   = x.CommandName;
         string PID   = x.Attributes["imgId"];
         string liked = x.ImageUrl;
         if (liked == "/Images/unlike.png")
         {
             if (LikeClass.sendLike(UID, PID) == true)
             {
                 x.ImageUrl = "/Images/like.png";
                 ListViewDataItem item     = (ListViewDataItem)(sender as Control).NamingContainer;
                 Label            lblTLike = (Label)item.FindControl("lblTLike");
                 lblTLike.Text = SqlTask.getTotalLikeByPhoto(PID).ToString();
             }
         }
         else if (liked == "/Images/like.png")
         {
             if (LikeClass.UnLike(UID, PID) == true)
             {
                 x.ImageUrl = "/Images/unlike.png";
                 ListViewDataItem item     = (ListViewDataItem)(sender as Control).NamingContainer;
                 Label            lblTLike = (Label)item.FindControl("lblTLike");
                 lblTLike.Text = SqlTask.getTotalLikeByPhoto(PID).ToString();
             }
         }
     }
 }
예제 #3
0
        void mainItem()
        {
            using (WebClient webClient = new WebClient())
            {
                _allComments = JsonConvert.DeserializeObject <List <Comments> >(webClient.DownloadString(WebUrlGetAllComments));
            }


            _listViewBind = new List <PhotoInfo>();
            try
            {
                if (conn.State != System.Data.ConnectionState.Closed)
                {
                    conn.Close();
                }
                conn.Open();
                cmd = new SqlCommand("SELECT TOP 20 U_ID,p_path,publish,rate,t_like,fname,sname,imgpath,PID,Url,Photos.Disc,Projects.Name FROM PHOTOS,USERS,PROJECTS WHERE U_ID=ID AND publish='1' AND Projects.Pro_ID=Photos.Pr_ID ORDER BY t_like DESC", conn);
                dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    _listViewBind.Add(new PhotoInfo()
                    {
                        UID         = dr[0].ToString(),
                        imgUrl      = "https://" + dr[1].ToString(),
                        userFName   = dr[5].ToString(),
                        userSName   = dr[6].ToString(),
                        userImg     = dr[7].ToString(),
                        publish     = dr[2].ToString(),
                        rate        = dr[3].ToString(),
                        tLike       = Convert.ToInt32(dr[4]),
                        PID         = dr[8].ToString(),
                        Url         = dr[9].ToString(),
                        Disc        = dr[10].ToString(),
                        projectname = dr[11].ToString(),
                    });
                }
                conn.Close();

                if (Session["loginuser"] != null)
                {
                    try
                    {
                        _listViewBind = LikeClass.getLiked(_listViewBind, Session["loginuser"].ToString());
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                foreach (PhotoInfo item in _listViewBind)
                {
                    //List<Comment> _newComent = new List<Comment>();
                    //var allCommentItems = _allComments.Where(db => db.P_ID == item.PID).ToList();
                    //foreach (var itemComments in allCommentItems)
                    //{
                    //    _newComent.Add(new Comment
                    //    {
                    //        CDate = Convert.ToDateTime(itemComments.CDate),
                    //        PID=itemComments.P_ID,
                    //        UID = itemComments.U_ID,
                    //        CText = itemComments.P_Comment,
                    //        UserUrl=item.Url,
                    //        UserFName = item.userFName,
                    //        UserSName = item.userSName,
                    //        UserImg = item.userImg,
                    //    });
                    //}
                    //item.CommentList = _newComent;
                    item.CommentList = SqlTask.GetCommentsByPhotoId(item.PID);
                    item.tComment    = item.CommentList.Count;
                    //item.tComment = SqlTask.GetTotalComment(item.PID);
                    switch (item.rate)
                    {
                    case "0":
                        item.imgStar = "/Images/0star.png";
                        break;

                    case "1":
                        item.imgStar = "/Images/1star.png";
                        break;

                    case "2":
                        item.imgStar = "/Images/2star.png";
                        break;

                    case "3":
                        item.imgStar = "/Images/3star.png";
                        break;

                    case "4":
                        item.imgStar = "/Images/4star.png";
                        break;

                    case "5":
                        item.imgStar = "/Images/5star.png";
                        break;

                    default:
                        item.imgStar = "/Images/0star.png";
                        break;
                    }
                }

                ListView1.DataSource = _listViewBind;
                ListView1.DataBind();
            }
            finally
            {
                conn.Close();
            }
        }