Ejemplo n.º 1
0
        public void datamagnet()
        {
            using (var dataBase = new NovelsModelContainer())
            {
                var queryNovel = from a in dataBase.Novels
                                 orderby a.Name
                                 select a;


                foreach (var item in queryNovel)
                {
                    novelinformation += item.Name + "\n" + "Chapters : " + item.Chapter + "\n" + "Genres : " + item.Genre + "\n\n";
                }
            }
        }
Ejemplo n.º 2
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     using (var dataBase = new NovelsModelContainer())
     {
         var queryNovel = from a in dataBase.Novels
                          orderby a.Name
                          select a;
         foreach (var item in queryNovel)
         {
             if (TextBox2.Text == item.Name)
             {
                 dataBase.Novels.Remove(item);
             }
         }
         dataBase.SaveChanges();
     }
     Response.Redirect(Request.RawUrl);
 }
Ejemplo n.º 3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (NovelChapter.Text.Length >= 1 && NovelText.Text.Length > 2)
            {
                try
                {
                    using (var dataBase = new NovelsModelContainer())
                    {
                        var novelName = NovelText.Text;
                        int novelChapter;
                        if (!Int32.TryParse(NovelChapter.Text, out novelChapter))
                        {
                            Label4.Visible = true;
                        }
                        else
                        {
                            Label4.Visible = false;
                            var geen    = "";
                            int counter = 1;
                            foreach (ListItem item in GenreCheckBox.Items)
                            {
                                if (item.Selected)
                                {
                                    if (counter > 1)
                                    {
                                        geen += ", " + item.Value;
                                    }

                                    else
                                    {
                                        geen += item.Value;
                                        counter++;
                                    }
                                }
                            }


                            var novel = new Novel {
                                Name = novelName, Chapter = novelChapter, Genre = geen
                            };
                            dataBase.Novels.Add(novel);
                            dataBase.SaveChanges();
                        }
                    }
                    NovelText.Text    = null;
                    NovelChapter.Text = null;
                    foreach (ListItem item in GenreCheckBox.Items)
                    {
                        item.Selected = false;
                    }
                }
                catch (DbEntityValidationException d)
                {
                    foreach (var eve in d.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
            else
            {
                Label4.Visible = true;
            }
        }