コード例 #1
0
    protected void CommentList_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        switch (e.Item.ItemType)
        {
        case ListViewItemType.DataItem:
        {
            TorrentComment comment    = (TorrentComment)e.Item.DataItem;
            User           user       = myEntities.Users.Where(u => u.UserName == comment.AuthorName).Single();
            HyperLink      authorLink = e.Item.FindControl("AuthorLink") as HyperLink;
            if (authorLink != null)
            {
                authorLink.NavigateUrl = "~/UserDetailsViews/UserDetails.aspx?Id=" + user.UID;
            }

            Image avatarImg = e.Item.FindControl("AvatarImg") as Image;
            if (avatarImg != null)
            {
                avatarImg.ImageUrl = user.AvatarUrl;
            }

            if (User.IsInRole("CHD") || User.Identity.Name == comment.AuthorName)
            {
                Button deleteButton = e.Item.FindControl("DeleteCommentButton") as Button;
                if (deleteButton != null)
                {
                    deleteButton.Visible = true;
                }
            }
        }
        break;
        }
    }
コード例 #2
0
    public void CommentList_DeleteItem(int id)
    {
        TorrentComment comment =
            myEntities.TorrentComments.Where(c => c.Id == id).Single();

        myEntities.TorrentComments.Remove(comment);
        myEntities.SaveChanges();
    }
コード例 #3
0
    public void CommentList_InsertItem()
    {
        TorrentComment comment = new TorrentComment();

        TryUpdateModel(comment);
        if (ModelState.IsValid)
        {
            comment.TorrentId      = _id;
            comment.CreateDateTime = DateTime.Now;
            comment.UpdateDateTime = comment.CreateDateTime;
            comment.AuthorName     = User.Identity.Name;
            myEntities.TorrentComments.Add(comment);
        }
        myEntities.SaveChanges();
    }