예제 #1
0
        public ValuesController(NewsContext context)
        {
            // i++;
            _context = context;

            List <News> newsList = new List <News>()
            {
                new News {
                    Title       = "Overskrift",
                    Author      = "Simon",
                    Content     = "Indhold",
                    CreatedDate = DateTime.Now.AddDays(-4),
                    UpdatedDate = DateTime.Now,
                    HashTags    = "#SimonErGud;#FedOpgave"
                },

                new News {
                    Title       = "Bob er syg!",
                    Author      = "julianbulian",
                    Content     = "han er så syg",
                    CreatedDate = DateTime.Now.AddDays(-3),
                    UpdatedDate = DateTime.Now,
                    HashTags    = "#FuckingSyg;#MorgenHår;#Dabtastic;#ForhåbentligRaskIgenSnart"
                },

                new News {
                    Title       = "Bob er rask!",
                    Author      = "julianbulian",
                    Content     = "Han er så rask!",
                    CreatedDate = DateTime.Now.AddDays(-2),
                    UpdatedDate = DateTime.Now,
                    HashTags    = "#FuckingRask;#Yay;#NearDeathExperience"
                },

                new News {
                    Title       = "Bob er syg, igen!",
                    Author      = "julianbulian",
                    Content     = "Bob var aldrig rask!",
                    CreatedDate = DateTime.Now.AddDays(-1),
                    UpdatedDate = DateTime.Now,
                    HashTags    = "#FuckMyLife;#Testamente;#ErDerFlereHashTags?;#HashTagHashTags"
                },
            };

            //}
            //{
            //    Title = "Overskrift",
            //    Author = "Simon",
            //    Content = "Indhold",
            //    CreatedDate = DateTime.Now.AddDays(-1),
            //    UpdatedDate = DateTime.Now,
            //    HashTags = "#SimonErGud;#FedOpgave"
            //};
            _context.AddRange(newsList);
            _context.SaveChanges();
        }
예제 #2
0
 public async Task SaveManyNews(IList <News> news)
 {
     try
     {
         _context.AddRange(news);
         await _context.SaveChangesAsync();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
예제 #3
0
        public static void SeedTheAuthors()
        {
            var author1 = new Author("Godzilla Hårddisksson");
            var author2 = new Author("Tord Yvel");
            var author3 = new Author("Billy Texas");

            using (var context = new NewsContext())
            {
                context.AddRange(author1, author2, author3);

                context.SaveChanges();
            }
        }
예제 #4
0
        public static void SeedTheCategories()
        {
            var category1 = new Category("Nyheter");
            var category2 = new Category("Ekonomi");
            var category3 = new Category("Sport");
            var category4 = new Category("Lokalt");
            var category5 = new Category("Inrikes");
            var category6 = new Category("Vetenskap");
            var category7 = new Category("Världen");

            using (var context = new NewsContext())
            {
                context.AddRange(category1, category2, category3, category4, category5, category6, category7);

                context.SaveChanges();
            }
        }
예제 #5
0
        public void SeedTheNews()
        {
            var context = new NewsContext();

            var news1 = new News();

            news1.Header   = "En fotbollsartikel";
            news1.Intro    = "Lorem ipsum dolor sit amet.";
            news1.Paragraf = "Some more text.";
            news1.Created  = DateTime.Now;
            news1.Updated  = DateTime.Now;

            var news2 = new News();

            news2.Header   = "En lokal artikel";
            news2.Intro    = "Lorem ipsum dolor sit amet.";
            news2.Paragraf = "Some more text.";
            news2.Created  = DateTime.Now;
            news2.Updated  = DateTime.Now;

            var news3 = new News();

            news3.Header   = "En krönika";
            news3.Intro    = "Lorem ipsum dolor sit amet.";
            news3.Paragraf = "Some more text.";
            news3.Created  = DateTime.Now;
            news3.Updated  = DateTime.Now;

            var news4 = new News();

            news4.Header   = "Ett reportage om Kicki Danielsson";
            news4.Intro    = "Lorem ipsum dolor sit amet.";
            news4.Paragraf = "Some more text.";
            news4.Created  = DateTime.Now;
            news4.Updated  = DateTime.Now;

            var news5 = new News();

            news5.Header   = "Ny kungabäbis";
            news5.Intro    = "Lorem ipsum dolor sit amet.";
            news5.Paragraf = "Some more text.";
            news5.Created  = DateTime.Now;
            news5.Updated  = DateTime.Now;

            using (context)
            {
                context.AddRange(news1, news2, news3, news4, news5);

                var result1 = context.Categories.Single(x => x.Id == 3);

                var result2 = context.Categories.Single(x => x.Id == 4);

                var result3 = context.Authors.Single(x => x.Id == 1);


                var newscategory1 = new NewsCategories()
                {
                    NewsId     = news1.Id,
                    CategoryId = result1.Id
                };

                var newscategory2 = new NewsCategories()
                {
                    NewsId     = news1.Id,
                    CategoryId = result2.Id
                };

                var newscategory3 = new NewsCategories()
                {
                    NewsId     = news2.Id,
                    CategoryId = result1.Id
                };

                var newscategory4 = new NewsCategories()
                {
                    NewsId     = news3.Id,
                    CategoryId = result1.Id
                };

                var authornews = new AuthorsNews(news1, result3);

                var authornews1 = new AuthorsNews(news2, result3);

                context.AddRange(newscategory1, newscategory2, newscategory3, newscategory4, authornews, authornews1);

                context.SaveChanges();
            }
        }