private void buttonAddNewT_Click(object sender, EventArgs e)
        {
            using (NewsContext NewsTable = new NewsContext())
            {
                NewsTable.NewT.Add(new New {
                    Basis = textBoxText.Text,
                    Head  = textBoxHead.Text
                });

                NewsTable.SaveChanges();
            }
        }
Пример #2
0
        private void buttonAddComment_Click(object sender, EventArgs e)
        {
            using (NewsContext NewsTable = new NewsContext())
            {
                Guid sd = ListNew[Count].Id;

                New newss = NewsTable.NewT
                            .Where(c => c.Id == sd)
                            .FirstOrDefault();

                NewsTable.CommentT.Add(new Comment {
                    Text  = textBoxCommentAdd.Text,
                    IdNew = newss
                });

                NewsTable.SaveChanges();
            }
        }
Пример #3
0
        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListNew.Count; i++)
            {
                ListNew.Remove(ListNew[i]);
                i--;
            }
            for (int i = 0; i < ListComment.Count; i++)
            {
                ListComment.Remove(ListComment[i]);
                i--;
            }
            labelComment.Text = "";

            using (NewsContext NewsTable = new NewsContext())
            {
                foreach (var i in NewsTable.NewT)
                {
                    ListNew.Add(i);
                }

                foreach (var i in NewsTable.CommentT)
                {
                    ListComment.Add(i);
                }

                if (ListNew.Count != 0)
                {
                    labelHead.Text = ListNew[0].Head;
                    labelText.Text = ListNew[0].Basis;
                    Count          = 0;
                }
            }

            foreach (var i in ListComment)
            {
                if (i.IdNew == ListNew[Count])
                {
                    labelComment.Text += i.Text + '\n' + '\n';
                }
            }
        }
Пример #4
0
        public Form1()
        {
            ListNew     = new List <New>();
            ListComment = new List <Comment>();

            InitializeComponent();
            userControlAddNew1.BringToFront();
            using (NewsContext NewsTable = new NewsContext())
            {
                NewsTable.Database.CreateIfNotExists();

                NewsTable.Database.Initialize(false);

                foreach (var i in NewsTable.NewT)
                {
                    ListNew.Add(i);
                }

                foreach (var i in NewsTable.CommentT)
                {
                    ListComment.Add(i);
                }

                if (ListNew.Count != 0)
                {
                    labelHead.Text = ListNew[0].Head;
                    labelText.Text = ListNew[0].Basis;
                    Count          = 0;
                }
            }

            foreach (var i in ListComment)
            {
                if (i.IdNew == ListNew[Count])
                {
                    labelComment.Text += i.Text + '\n' + '\n';
                }
            }
        }