Esempio n. 1
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BooksDbContext context = application.ApplicationServices.
                                     CreateScope().ServiceProvider.GetRequiredService <BooksDbContext>();



            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.Books.Any())
            {
                context.Books.AddRange
                (
                    new Book
                {
                    Title     = "Les Miserables",
                    AuthFirst = "Victor",
                    AuthLast  = "Hugo",
                    Publisher = "Signet",
                    ISBN      = 9780451419439,
                    Classif   = "Fiction",
                    Category  = "Classic",
                    Price     = 9.95,
                    PageCount = 1488
                },
                    new Book
                {
                    Title     = "Team of Rivals",
                    AuthFirst = "Doris Kearns",
                    AuthLast  = "Goodwin",
                    Publisher = "Simon and Schuster",
                    ISBN      = 9780743270755,
                    Classif   = "Non-Fiction",
                    Category  = "Biography",
                    Price     = 14.58,
                    PageCount = 944
                },
                    new Book
                {
                    Title     = "The Snowball",
                    AuthFirst = "Alice",
                    AuthLast  = "Schroeder",
                    Publisher = "Bantam",
                    ISBN      = 9780553384611,
                    Classif   = "Non-Fiction",
                    Category  = "Biography",
                    Price     = 21.54,
                    PageCount = 832
                },
                    new Book
                {
                    Title     = "American Ulysses",
                    AuthFirst = "Ronald C.",
                    AuthLast  = "White",
                    Publisher = "Random House",
                    ISBN      = 9780812981254,
                    Classif   = "Non-Fiction",
                    Category  = "Biography",
                    Price     = 11.61,
                    PageCount = 864
                },
                    new Book
                {
                    Title     = "Unbroken",
                    AuthFirst = "Laura",
                    AuthLast  = "Hillenbrand",
                    Publisher = "Random House",
                    ISBN      = 9780812974492,
                    Classif   = "Non-Fiction",
                    Category  = "Historical",
                    Price     = 13.33,
                    PageCount = 528
                },
                    new Book
                {
                    Title     = "The Great Train Robbery",
                    AuthFirst = "Michael",
                    AuthLast  = "Crichton",
                    Publisher = "Vintage",
                    ISBN      = 9780804171281,
                    Classif   = "Fiction",
                    Category  = "Historical Fiction",
                    Price     = 15.95,
                    PageCount = 288
                },
                    new Book
                {
                    Title     = "Deep Work",
                    AuthFirst = "Cal",
                    AuthLast  = "Newport",
                    Publisher = "Grand Central Publishing",
                    ISBN      = 9781455586691,
                    Classif   = "Non-Fiction",
                    Category  = "Self-Help",
                    Price     = 14.99,
                    PageCount = 304
                },
                    new Book
                {
                    Title     = "It's Your Ship",
                    AuthFirst = "Michael",
                    AuthLast  = "Abrashoff",
                    Publisher = "Grand Central Publishing",
                    ISBN      = 9781455523023,
                    Classif   = "Non-Fiction",
                    Category  = "Self-Help",
                    Price     = 21.66,
                    PageCount = 240
                },
                    new Book
                {
                    Title     = "The Virgin Way",
                    AuthFirst = "Richard",
                    AuthLast  = "Branson",
                    Publisher = "Portfolio",
                    ISBN      = 9781591847984,
                    Classif   = "Non-Fiction",
                    Category  = "Business",
                    Price     = 29.16,
                    PageCount = 400
                },
                    new Book
                {
                    Title     = "Sycamore Row",
                    AuthFirst = "John",
                    AuthLast  = "Grisham",
                    Publisher = "Bantam",
                    ISBN      = 9780553393613,
                    Classif   = "Fiction",
                    Category  = "Thrillers",
                    Price     = 15.03,
                    PageCount = 642
                },
                    new Book
                {
                    Title     = "Anxious People",
                    AuthFirst = "Frederick",
                    AuthLast  = "Backman",
                    Publisher = "Simon and Schuster",
                    ISBN      = 9788770366038,
                    Classif   = "Fiction",
                    Category  = "Novel",
                    Price     = 20.00,
                    PageCount = 352
                },
                    new Book
                {
                    Title     = "A man Called Ove",
                    AuthFirst = "Fredrik",
                    AuthLast  = "Backman",
                    Publisher = "Simon and Schuster",
                    ISBN      = 9780718186616,
                    Classif   = "Fiction",
                    Category  = "Novel",
                    Price     = 8.98,
                    PageCount = 368
                },
                    new Book
                {
                    Title     = "Daring Greatly",
                    AuthFirst = "Brene",
                    AuthLast  = "Brown",
                    Publisher = "Penguin Books",
                    ISBN      = 9785768087734,
                    Classif   = "Non-Fiction",
                    Category  = "Self-Help",
                    PageCount = 322
                }
                );

                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BooksDbContext context = application.ApplicationServices.
                                     CreateScope().ServiceProvider.GetRequiredService <BooksDbContext>();

            //if any migrations need to happen, then migrate

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.Books.Any())
            //seeded data!
            {
                context.Books.AddRange(
                    new Books
                {
                    Title          = "Les Miserables",
                    AuthorFirst    = "Victor",
                    AuthorLast     = "Hugo",
                    Publisher      = "Signet",
                    ISBN           = "978-0451419439",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 9.95F,
                    PagesNum       = 1448
                },
                    new Books
                {
                    Title          = "Team of Rivals",
                    AuthorFirst    = "Doris",
                    AuthorMiddle   = "Kearns",
                    AuthorLast     = "Goodwin",
                    Publisher      = "Simon & Schuster",
                    ISBN           = "978-0743270755",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 14.58F,
                    PagesNum       = 944
                },
                    new Books
                {
                    Title          = "The Snowball",
                    AuthorFirst    = "Alice",
                    AuthorLast     = "Schroeder",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553384611",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 21.54F,
                    PagesNum       = 832
                },
                    new Books
                {
                    Title          = "American Ulysses",
                    AuthorFirst    = "Ronald",
                    AuthorMiddle   = "C.",
                    AuthorLast     = "White",
                    Publisher      = "Random House",
                    ISBN           = "978-0812981254",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 11.61F,
                    PagesNum       = 864
                },
                    new Books
                {
                    Title          = "Unbroken",
                    AuthorFirst    = "Laura",
                    AuthorLast     = "Hillenbrand",
                    Publisher      = "Random House",
                    ISBN           = "978-0812974492",
                    Classification = "Non-Fiction",
                    Category       = "Historical",
                    Price          = 13.33F,
                    PagesNum       = 528
                },
                    new Books
                {
                    Title          = "The Great Train Robbery",
                    AuthorFirst    = "Michael",
                    AuthorLast     = "Crichton",
                    Publisher      = "Vintage",
                    ISBN           = "978-0804171281",
                    Classification = "Fiction",
                    Category       = "Historical",
                    Price          = 15.95F,
                    PagesNum       = 288
                },
                    new Books
                {
                    Title          = "Deep Work",
                    AuthorFirst    = "Cal",
                    AuthorLast     = "Newport",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455586691",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 14.99F,
                    PagesNum       = 304
                },
                    new Books
                {
                    Title          = "It's Your Ship",
                    AuthorFirst    = "Michael",
                    AuthorLast     = "Abrashoff",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455523023",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 21.66F,
                    PagesNum       = 240
                },
                    new Books
                {
                    Title          = "The Virgin Way",
                    AuthorFirst    = "Richard",
                    AuthorLast     = "Branson",
                    Publisher      = "Portfolio",
                    ISBN           = "978-1591847984",
                    Classification = "Non-Fiction",
                    Category       = "Business",
                    Price          = 29.16F,
                    PagesNum       = 400
                },
                    new Books
                {
                    Title          = "Sycamore Row",
                    AuthorFirst    = "John",
                    AuthorLast     = "Grisham",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553393613",
                    Classification = "Fiction",
                    Category       = "Thrillers",
                    Price          = 15.03F,
                    PagesNum       = 642
                },
                    new Books
                {
                    Title          = "The Mysterious Benedict Society",
                    AuthorFirst    = "Trenton",
                    AuthorMiddle   = "Lee",
                    AuthorLast     = "Stewart",
                    Publisher      = "Little, Brown and Company",
                    ISBN           = "978-6003956456",
                    Classification = "Fiction",
                    Category       = "Mystery",
                    Price          = 9.83F,
                    PagesNum       = 512
                },
                    new Books
                {
                    Title          = "Jane Eyre",
                    AuthorFirst    = "Charlotte",
                    AuthorLast     = "Bronte",
                    Publisher      = "Smith, Elder & Co.",
                    ISBN           = "978-0141441146",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 4.99F,
                    PagesNum       = 480
                },
                    new Books
                {
                    Title          = "Where the Red Fern Growsw",
                    AuthorFirst    = "Wilson",
                    AuthorLast     = "Rawls",
                    Publisher      = "Doubleday",
                    ISBN           = "978-0440412670",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 6.19F,
                    PagesNum       = 304
                }

                    );
                //save data
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public static void EnsurePopulated(IApplicationBuilder application)

        {
            BooksDbContext context = application.ApplicationServices.CreateScope().ServiceProvider.GetRequiredService <BooksDbContext>();

            //This if checks if there are any pending migrations
            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (!context.Projects.Any())
            {
                context.Projects.AddRange(

                    //This is where the data is created for each book
                    new Project
                {
                    Title          = "Les Miserable",
                    Author         = "Victor Hugo",
                    Publisher      = "Signet",
                    ISBN           = "978-0451419439",
                    Classification = "Fiction, Classic",
                    Price          = 9.95,
                    PageNumbers    = 1488
                },

                    new Project
                {
                    Title          = "Team of Rivals",
                    Author         = "Doris Kearns Goodwin",
                    Publisher      = "Simon & Schuster",
                    ISBN           = "978-0743270755",
                    Classification = "Non-Fiction, Biography",
                    Price          = 14.58,
                    PageNumbers    = 944
                },

                    new Project
                {
                    Title          = "The Snowball",
                    Author         = "Alice Schroeder",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553384611",
                    Classification = "Non-Fiction, Biography",
                    Price          = 21.54,
                    PageNumbers    = 832
                },

                    new Project
                {
                    Title          = "American Ulysses",
                    Author         = "Ronald C. White",
                    Publisher      = "Random House",
                    ISBN           = "978-0812981254",
                    Classification = "Non-Fiction, Biography",
                    Price          = 11.61,
                    PageNumbers    = 864
                },

                    new Project
                {
                    Title          = "Unbroken",
                    Author         = "Laura Hillenbrand",
                    Publisher      = "Random House",
                    ISBN           = "978-0812974492",
                    Classification = "Non-Fiction, Historical",
                    Price          = 13.33,
                    PageNumbers    = 528
                },

                    new Project
                {
                    Title          = "The Great Train Robbery",
                    Author         = "Michael Crichton",
                    Publisher      = "Vintage",
                    ISBN           = "978-0804171281",
                    Classification = "Fiction, Historical Fiction",
                    Price          = 15.95,
                    PageNumbers    = 288
                },

                    new Project
                {
                    Title          = "Deep Work",
                    Author         = "Cal Newport",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455586691",
                    Classification = "Non-Fiction, Self-Help",
                    Price          = 14.99,
                    PageNumbers    = 304
                },

                    new Project
                {
                    Title          = "It's Your Ship",
                    Author         = "Michael Abrashoff",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455523023",
                    Classification = "Non-Fiction, Self-Help",
                    Price          = 21.66,
                    PageNumbers    = 240
                },

                    new Project
                {
                    Title          = "The Virgin Way",
                    Author         = "Richard Branson",
                    Publisher      = "Portfolio",
                    ISBN           = "978-1591847984",
                    Classification = "Non-Fiction, Business",
                    Price          = 29.16,
                    PageNumbers    = 400
                },

                    new Project
                {
                    Title          = "Sycamore Row",
                    Author         = "John Grisham",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553393613",
                    Classification = "Fiction, Thrillers",
                    Price          = 15.03,
                    PageNumbers    = 642
                },

                    new Project
                {
                    Title          = "Book of Mormon",
                    Author         = "God",
                    Publisher      = "The Church of Jesus Christ of Latter-day Saints",
                    ISBN           = "978-0530829500",
                    Classification = "Religous, Historical",
                    Price          = 3.10,
                    PageNumbers    = 531
                },

                    new Project
                {
                    Title          = "The Great Gatsby",
                    Author         = "F. Scott Fitzgerald",
                    Publisher      = "Charles Scribner's Sons",
                    ISBN           = "978-0743273565",
                    Classification = "Fiction, Tragedy",
                    Price          = 4.79,
                    PageNumbers    = 218
                },

                    new Project
                {
                    Title          = "The Ferguson Rifle",
                    Author         = "Louis L'Amour",
                    Publisher      = "Bantam",
                    ISBN           = "978-0804126618",
                    Classification = "Western, Fiction",
                    Price          = 4.49,
                    PageNumbers    = 240
                }


                    );

                context.SaveChanges();
            }
        }
Esempio n. 4
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BooksDbContext context = application.ApplicationServices.
                                     CreateScope().ServiceProvider.GetRequiredService <BooksDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (!context.Books.Any())
            {
                context.Books.AddRange(
                    // Load up all of the data to be stored in the database at first
                    new Book
                {
                    Title          = "Les Miserables",
                    AuthFirst      = "Victor",
                    AuthLast       = "Hugo",
                    Publisher      = "Signet",
                    ISBN           = "978-0451419439",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 9.95
                },
                    new Book
                {
                    Title          = "Team of Rivals",
                    AuthFirst      = "Doris",
                    AuthMid        = "Kearns",
                    AuthLast       = "Goodwin",
                    Publisher      = "Simon & Schuster",
                    ISBN           = "978-0743270755",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 14.58
                },
                    new Book
                {
                    Title          = "The Snowball",
                    AuthFirst      = "Alice",
                    AuthLast       = "Schroeder",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553384611",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 21.54
                },
                    new Book
                {
                    Title          = "American Ulysses",
                    AuthFirst      = "Ronald",
                    AuthMid        = "C.",
                    AuthLast       = "White",
                    Publisher      = "Random House",
                    ISBN           = "978-0812981254",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 11.61
                },
                    new Book
                {
                    Title          = "Unbroken",
                    AuthFirst      = "Laura Hillenbrand",
                    AuthLast       = "",
                    Publisher      = "Random House",
                    ISBN           = "978-0812974492",
                    Classification = "Non-Fiction",
                    Category       = "Historical",
                    Price          = 13.33
                },
                    new Book
                {
                    Title          = "The Great Train Robbery",
                    AuthFirst      = "Michael Crichton",
                    AuthLast       = "",
                    Publisher      = "Vintage",
                    ISBN           = "978-0804171281",
                    Classification = "Fiction",
                    Category       = "Historical Fiction",
                    Price          = 15.95
                },
                    new Book
                {
                    Title          = "Deep Work",
                    AuthFirst      = "Cal Newport",
                    AuthLast       = "",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455586691",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 14.99
                },
                    new Book
                {
                    Title          = "It's Your Ship",
                    AuthFirst      = "Michael Abrashoff",
                    AuthLast       = "",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455523023",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 21.66
                },
                    new Book
                {
                    Title          = "The Virgin Way",
                    AuthFirst      = "Richard Branson",
                    AuthLast       = "",
                    Publisher      = "Portfolio",
                    ISBN           = "978-1591847984",
                    Classification = "Non-Fiction",
                    Category       = "Business",
                    Price          = 29.16
                },
                    new Book
                {
                    Title          = "Sycamore Row",
                    AuthFirst      = "John Grisham",
                    AuthLast       = "",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553393613",
                    Classification = "Fiction",
                    Category       = "Thrillers",
                    Price          = 15.03
                }
                    );

                context.SaveChanges();
            }
        }
Esempio n. 5
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BooksDbContext context = application.ApplicationServices.
                                     CreateScope().ServiceProvider.GetRequiredService <BooksDbContext>();

            //Migrates data if there are pending migrations

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            //Seeds datab if there are no saved data
            if (!context.Books.Any())
            {
                context.Books.AddRange(
                    new Books
                {
                    Title           = "Les Miserables",
                    AuthorFirstName = "Victor",
                    AuthorLastName  = "Hugo",
                    Publisher       = "Signet",
                    ISBN            = "978-0451419439",
                    Classification  = "Fiction",
                    Category        = "Classic",
                    Price           = 9.95
                },
                    new Books
                {
                    Title           = "Team of Rivals",
                    AuthorFirstName = "Doris Kearns",
                    AuthorLastName  = "Goodwin",
                    Publisher       = "Simon & Schuster",
                    ISBN            = "978-0743270755",
                    Classification  = "Non-Fiction",
                    Category        = "Biography",
                    Price           = 14.58
                },
                    new Books
                {
                    Title           = "The Snowball",
                    AuthorFirstName = "Alice",
                    AuthorLastName  = "Schroeder",
                    Publisher       = "Bantam",
                    ISBN            = "978-0553384611",
                    Classification  = "Non-Fiction",
                    Category        = "Biography",
                    Price           = 21.54
                },
                    new Books
                {
                    Title           = "American Ulysses",
                    AuthorFirstName = "Ronald C.",
                    AuthorLastName  = "White",
                    Publisher       = "Random House",
                    ISBN            = "978-0812981254",
                    Classification  = "Non-Fiction",
                    Category        = "Historical",
                    Price           = 11.61
                },
                    new Books
                {
                    Title           = "The Great Train Robbery",
                    AuthorFirstName = "Michael",
                    AuthorLastName  = "Crichton",
                    Publisher       = "Vintage",
                    ISBN            = "978-0804171281",
                    Classification  = "Fiction",
                    Category        = "Historical Fiction",
                    Price           = 13.33
                },
                    new Books
                {
                    Title           = "Deep Work",
                    AuthorFirstName = "Cal",
                    AuthorLastName  = "Newport",
                    Publisher       = "Grand Central Publishing",
                    ISBN            = "978-1455586691",
                    Classification  = "Non-Fiction",
                    Category        = "Self-Help",
                    Price           = 13.33
                }

                    );

                context.SaveChanges();
            }
        }