Exemplo n.º 1
0
        private void PostForm_Load(object sender, EventArgs e)
        {
            chooseBlogComboBox.Items.Add("Choose a blog...");
            chooseBlogComboBox.SelectedItem = chooseBlogComboBox.Items[0];

            using (BlogContext context = new BlogContext())
            {
                var blogs = from b in context.Blogs
                            orderby b.Name
                            select b.Name;

                foreach (var item in blogs)
                {
                    chooseBlogComboBox.Items.Add(item);
                }

            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            String name;

            Console.WriteLine("Na wstępie stworzymy testowo nowego bloga");
            Console.WriteLine("Podaj nazwe nowego bloga:");

            name = Console.ReadLine();

            using (BlogContext context = new BlogContext())
            {
                context.Database.Log = message => Trace.WriteLine(message);

                Blog blog = new Blog { Name = name };
                context.Blogs.Add(blog);
                context.SaveChanges();

                var query = context.Blogs.Select(b => b).OrderBy(b => b.Name);

                foreach (var item in query)
                {
                    Console.WriteLine("Nazwa bloga: " + item.Name + "\n");
                }

                Console.WriteLine("---------------------------------------------");
                Console.WriteLine("MB::Console:");

                var mbQuery = context.Blogs.Select(b => b.Name).OrderBy(n => n);

                foreach (var item in mbQuery)
                {
                    Console.WriteLine("* " + item);
                }

                BlogForm bf = new BlogForm();
                bf.ShowDialog();
            }

            Console.ReadLine();
        }
Exemplo n.º 3
0
        private void confirmAddingNewPostButton_Click(object sender, EventArgs e)
        {
            using (BlogContext context = new BlogContext())
            {
                _blogId = (from b in context.Blogs
                           where b.Name == chooseBlogComboBox.SelectedItem.ToString()
                           select b.BlogId).FirstOrDefault();
            }

            Post post = new Post()
            {
                BlogId = _blogId,
                Desc = descriptionOfNewPostTextBox.Text,
                Title = titleOfNewPostTextBox.Text
            };

            _bc.Posts.Add(post);

            _bc.SaveChanges();

            PostForm.ActiveForm.Close();
        }
Exemplo n.º 4
0
 public FindingForm(BlogContext bc)
 {
     InitializeComponent();
     this._bc = bc;
 }
Exemplo n.º 5
0
 public PostForm(BlogContext bc)
 {
     // TODO: Complete member initialization
     InitializeComponent();
     this._bc = bc;
 }