Exemplo n.º 1
0
        protected void like_Click(object sender, EventArgs e)
        {
            LikesManager       likesManager       = new LikesManager();
            CalculationManager calculationManager = new CalculationManager();
            int UserId    = int.Parse(((Session["user"] as User).Id).ToString());
            int ProjectId = int.Parse(Request.QueryString["Id"]);

            Model.Likes likes = likesManager.GetModelByUserIdAndProjectId(UserId, ProjectId);
            if (likes == null)
            {
                if (likesManager.Insert(UserId, ProjectId) > 0 && calculationManager.LikeCountAddition(ProjectId) > 0)
                {
                    Response.Write("<script>alert('关注成功!!');loaction.href='Projectinfo.aspx';</script>");
                    this.like.Text = "取消关注";
                    Response.Write("<script> window.location.href = document.URL; </script>");
                }
                else
                {
                    Response.Write("<script>alert('关注失败!!');</script>");
                }
            }
            else
            {
                if (likesManager.Delete(UserId, ProjectId) > 0 && calculationManager.LikeCountSubtraction(ProjectId) > 0)
                {
                    Response.Write("<script>alert('已取消关注!!');</script>");
                    this.like.Text = "关注";
                    Response.Write("<script> window.location.href = document.URL; </script>");
                }
                else
                {
                    Response.Write("<script>alert('取消失败!!');</script>");
                }
            }
        }