protected void Page_Load(object sender, EventArgs e)
    {
        using (var context = new rheaxuEntities())
        {
            int smId = Convert.ToInt32(Request["smId"]);
            memberSheetMusic msmObj = context.memberSheetMusics.SingleOrDefault(mSM => mSM.Id == smId);

            List <memberSheetMusic> msmObjList = new List <memberSheetMusic>();
            msmObjList.Add(msmObj);

            detailsmRepeater.DataSource = msmObjList;
            detailsmRepeater.DataBind();
            var likes = (from s in context.userLikeSms where s.smId == smId select s).Count();
            likeCountLabel.Text = "Likes: " + likes.ToString();

            List <sheetMusicComment> pCmntObjList = (from s in context.sheetMusicComments where s.smId == smId orderby s.createTime descending select s).ToList();
            CmntCountLabel.Text     = pCmntObjList.Count() + " comments for this sheet music";
            cmntRepeater.DataSource = pCmntObjList;
            cmntRepeater.DataBind();

            var likeUsersList = (from s in context.userLikeSms where s.smId == smId select s).ToList();
            likeUserRepeater.DataSource = likeUsersList;
            likeUserRepeater.DataBind();
        }
    }
    protected void likeBtn_Click(object sender, EventArgs e)
    {
        using (var context = new rheaxuEntities())
        {
            string likeTxt = likeBtn.Text;
            int    smId    = Convert.ToInt32(Request["smId"]);
            if (likeTxt == "Like")
            {
                userLikeSm uli = new userLikeSm {
                    smId = smId, username = User.Identity.Name
                };
                context.userLikeSms.Add(uli);
                memberSheetMusic msmObj = (from p in context.memberSheetMusics where p.Id == smId select p).FirstOrDefault();
                msmObj.likes += 1;
                context.SaveChanges();
                likeBtn.CssClass = "orange btn-sm";
                likeBtn.Text     = "Unlike";
            }
            else
            {
                string visitorname = User.Identity.Name;
                //userLikeImg uli = context.userLikeImgs.SingleOrDefault(visitor => visitor.username == visitorname);
                var uli = (from s in context.userLikeSms where s.username == visitorname && s.smId == smId select s).FirstOrDefault();
                context.userLikeSms.Remove(uli);
                memberSheetMusic msmObj = (from p in context.memberSheetMusics where p.Id == smId select p).FirstOrDefault();
                msmObj.likes -= 1;
                context.SaveChanges();
                likeBtn.CssClass = "blue btn-sm";
                likeBtn.Text     = "Like";
            }

            var likes = (from s in context.userLikeSms where s.smId == smId select s).Count();
            likeCountLabel.Text = "Likes: " + likes.ToString();
        }
    }
 protected void addToGallery_Click(object sender, EventArgs e)
 {
     using (var context = new rheaxuEntities())
     {
         int smId = Convert.ToInt32(Request["smId"]);
         memberSheetMusic msmObj     = (from s in context.memberSheetMusics where s.Id == smId select s).FirstOrDefault();
         string           custom_url = msmObj.smurl;
         Response.Redirect("postSheetMusic.aspx?custom_url=" + custom_url);
     }
 }
    protected void PostBtn_Click(object sender, EventArgs e)
    {
        using (var context = new rheaxuEntities())
        {
            memberSheetMusic msm = new memberSheetMusic {
                smurl = UrlTxt.Text, smTitle = TitleTxt.Text, smDesc = DescriptionArea.Text, ownername = User.Identity.Name, createTime = System.DateTime.Now, likes = 0
            };
            context.memberSheetMusics.Add(msm);
            context.SaveChanges();

            int nPId = msm.Id;
            UploadStatusLabel.Text = "Successfully added photot '" + msm.smTitle + "' to your collection";
            Response.Redirect("sheetMusicDetail.aspx?ownername=" + User.Identity.Name + "&smId=" + nPId);
        }
        //PhotoDAO dao = new PhotoDAO();
        //Photo photo = new Photo(UrlTxt.Text, User.Identity.Name, TitleTxt.Text, DescriptionArea.Text,0);
        //string uid = Page.User.Identity.Name;

        //int nPId = dao.insertPhotoInfo(photo);
        //UploadStatusLabel.Text = "Successfully added sheet music '" + photo.imgTitle+"' to your collectionn";
        //Response.Redirect("sheetMusicDetail.aspx?ownername=" + User.Identity.Name+"smId="+nPId);
    }