示例#1
0
        protected void SaveTagsBtn_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (db.WebPages.Where(p => p.RawURL.Equals(Request.RawUrl)).Count() <= 0)
                {
                    WebPage newPage = new WebPage()
                    {
                        id     = db.WebPages.Count() > 0 ? db.WebPages.OrderBy(p => p.id).ToList().Last().id + 1 : 0,
                        RawURL = Request.RawUrl,
                        Name   = TitleInput.Text
                    };
                    db.WebPages.Add(newPage);
                    db.SaveChanges();
                }

                WebPage page = db.WebPages.Where(p => p.RawURL.Equals(Request.RawUrl)).Single();

                page.Tags.Clear();

                foreach (int id in TagSelector1.GroupIds)
                {
                    WebPageTag tag = db.WebPageTags.Where(p => p.id == id).Single();
                    page.Tags.Add(tag);
                }

                db.SaveChanges();
            }
        }
        protected void CreateTagBtn_Click(object sender, EventArgs e)
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                if (db.WebPageTags.Where(t => t.Name.Equals(NewTagNameInput.Text)).Count() > 0)
                {
                    WebPageTag tag = db.WebPageTags.Where(t => t.Name.Equals(NewTagNameInput.Text)).Single();
                    AddTag(tag.id);
                    return;
                }

                WebPageTag newTag = new WebPageTag()
                {
                    id   = db.WebPageTags.Count() > 0 ? db.WebPageTags.OrderBy(t => t.id).ToList().Last().id + 1 : 0,
                    Name = NewTagNameInput.Text
                };

                db.WebPageTags.Add(newTag);
                db.SaveChanges();
                AddTag(newTag.id);
            }
        }
        protected void LoadTable()
        {
            using (WebhostEntities db = new WebhostEntities())
            {
                SelectedTable.Rows.Clear();
                if (GroupIds.Count == 0)
                {
                    RemoveBtn.Visible  = false;
                    RemoveList.Visible = false;
                    return;
                }
                foreach (int id in GroupIds)
                {
                    WebPageTag tag = db.WebPageTags.Where(f => f.id == id).Single();

                    TableRow  row  = new TableRow();
                    TableCell cell = new TableCell();
                    Label     lbl  = new Label()
                    {
                        Text = tag.Name
                    };

                    cell.Controls.Add(lbl);

                    row.Cells.Add(cell);
                    SelectedTable.Rows.Add(row);
                }

                RemoveList.Visible = true;
                RemoveBtn.Visible  = true;

                RemoveList.DataSource     = db.WebPageTags.Where(p => GroupIds.Contains(p.id)).ToList();
                RemoveList.DataTextField  = "Name";
                RemoveList.DataValueField = "id";
                RemoveList.DataBind();
            }
        }