コード例 #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            var selectedBlog = (string)comboBox1.SelectedItem;
            int blogId;

            //check validation
            using (var ctx = new BlogContext())    {
                blogId = (from b in ctx.Blogs where b.Name == selectedBlog select b.BlogId).FirstOrDefault();
                if (blogId == 0)    {
                    MessageBox.Show("You've not selected any blogs.");
                    return;
                }
            }
            if (textBox1.Text == "")    {
                MessageBox.Show("There is no title");
                return;
            }
            if (richTextBox1.Text == "")    {
                MessageBox.Show("No content");
                return;
            }
            var post = new Post();
            post.BlogId = blogId;
            post.Content = richTextBox1.Text;
            post.Title = textBox1.Text;
            //add and save post
            using (var ctx = new BlogContext())    {
                ctx.Posts.Add(post);
                ctx.SaveChanges();
            }
            Hide();
            DestroyHandle();
        }
コード例 #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            var selectedBlog = (string)comboBox1.SelectedItem;
            int blogId;

            //check validation
            using (var ctx = new BlogContext())    {
                blogId = (from b in ctx.Blogs where b.Name == selectedBlog select b.BlogId).FirstOrDefault();
                if (blogId == 0)
                {
                    MessageBox.Show("You've not selected any blogs.");
                    return;
                }
            }
            if (textBox1.Text == "")
            {
                MessageBox.Show("There is no title");
                return;
            }
            if (richTextBox1.Text == "")
            {
                MessageBox.Show("No content");
                return;
            }
            var post = new Post();

            post.BlogId  = blogId;
            post.Content = richTextBox1.Text;
            post.Title   = textBox1.Text;
            //add and save post
            using (var ctx = new BlogContext())    {
                ctx.Posts.Add(post);
                ctx.SaveChanges();
            }
            Hide();
            DestroyHandle();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Podaj nazwę bloga: ");
            String blogName = Console.ReadLine();
            Blog firstBlog = new Blog { Name = blogName };
            BlogContext blogContext = new BlogContext();
            blogContext.Blogs.Add(firstBlog);
            blogContext.SaveChanges();

            printBlogs(blogContext);
            //listBlogsAndPosts(blogContext);
            //listBlogsAndPostsNav(blogContext);
            listBlogsAndPostsNavQuery(blogContext);
            countPosts(blogContext);

            BlogForm form = new BlogForm();
            form.ShowDialog();

            Console.ReadLine();
        }
コード例 #4
0
 private void blogBindingNavigatorSaveItem_Click(object sender, EventArgs e)
 {
     bContext.SaveChanges();
 }