Esempio n. 1
0
    protected void likeBtn_Click(object sender, EventArgs e)
    {
        using (var context = new rheaxuEntities())
        {
            string likeTxt = likeBtn.Text;
            int    imgId   = Convert.ToInt32(Request["imgId"]);
            if (likeTxt == "Like")
            {
                userLikeImg uli = new userLikeImg {
                    photoId = imgId, username = User.Identity.Name
                };
                context.userLikeImgs.Add(uli);
                memberPhoto mpObj = (from p in context.memberPhotos where p.Id == imgId select p).FirstOrDefault();
                mpObj.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.userLikeImgs where s.username == visitorname && s.photoId == imgId select s).FirstOrDefault();
                context.userLikeImgs.Remove(uli);
                memberPhoto mpObj = (from p in context.memberPhotos where p.Id == imgId select p).FirstOrDefault();
                mpObj.likes -= 1;
                context.SaveChanges();
                likeBtn.CssClass = "blue btn-sm";
                likeBtn.Text     = "Like";
            }

            var likes = (from s in context.userLikeImgs where s.photoId == imgId select s).Count();
            likeCountLabel.Text = "Likes: " + likes.ToString();
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var context = new rheaxuEntities())
        {
            int         imgId     = Convert.ToInt32(Request["imgId"]);
            memberPhoto mPhotoObj = context.memberPhotos.SingleOrDefault(mPhoto => mPhoto.Id == imgId);

            List <memberPhoto> mPhotoObjList = new List <memberPhoto>();
            mPhotoObjList.Add(mPhotoObj);

            detailimgRepeater.DataSource = mPhotoObjList;
            detailimgRepeater.DataBind();
            var likes = (from s in context.userLikeImgs where s.photoId == imgId select s).Count();
            likeCountLabel.Text = "Likes: " + likes.ToString();

            List <photoComment> pCmntObjList = (from s in context.photoComments where s.pId == imgId orderby s.createTime descending select s).ToList();
            CmntCountLabel.Text     = pCmntObjList.Count() + " comments for this photo";
            cmntRepeater.DataSource = pCmntObjList;
            cmntRepeater.DataBind();

            var likeUsersList = (from s in context.userLikeImgs where s.photoId == imgId select s).ToList();
            likeUserRepeater.DataSource = likeUsersList;
            likeUserRepeater.DataBind();
        }
    }
Esempio n. 3
0
 protected void addToGallery_Click(object sender, EventArgs e)
 {
     using (var context = new rheaxuEntities())
     {
         int         imgId  = Convert.ToInt32(Request["imgId"]);
         memberPhoto pObj   = (from s in context.memberPhotos where s.Id == imgId select s).FirstOrDefault();
         string      imgUrl = pObj.imgurl;
         Response.Redirect("postPhoto.aspx?toAddImgUrl=" + imgUrl);
     }
 }
    protected void PostBtn_Click(object sender, EventArgs e)
    {
        using (var context = new rheaxuEntities())
        {
            memberPhoto mp = new memberPhoto {
                imgurl = UrlTxt.Text, imgTitle = TitleTxt.Text, imgDesc = DescriptionArea.Text, ownername = User.Identity.Name, createTime = System.DateTime.Now, likes = 0
            };
            context.memberPhotos.Add(mp);
            context.SaveChanges();

            int nPId = mp.Id;
            UploadStatusLabel.Text = "Successfully added photot '" + mp.imgTitle + "' to your collection";
            Response.Redirect("photoDetail.aspx?ownername=" + User.Identity.Name + "&imgId=" + nPId);
        }
    }