예제 #1
0
        private static void CreateChildren(EFContext context, string name, string parentUrlSlug, string urlSlug)
        {
            TreeViewCategoryElement parent = context.Categories.FirstOrDefault(x => x.UrlSlug == parentUrlSlug);

            if (parent != null)
            {
                context.Categories.Add(new TreeViewCategoryElement {
                    Name    = name,
                    UrlSlug = urlSlug,
                    Parent  = parent
                });

                context.SaveChanges();
            }
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtName.Text))
            {
                ComboBoxModel parentData = this.cbParents.SelectedItem as ComboBoxModel;

                TreeViewCategoryElement newEl = new TreeViewCategoryElement {
                    Name    = this.txtName.Text,
                    UrlSlug = this.txtName.Text.ToLower().Replace(' ', '-'),
                    Parent  = this._context.Categories.First(x => x.Id == parentData.Id)
                };
                this._context.Categories.Add(newEl);
                this._context.SaveChanges();
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Заповніть усі поля!");
            }
        }