Example #1
0
 //Constructor
 public EFBookstoreRepository(BookstoreDbContext context)
 {
     _context = context;
 }
Example #2
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BookstoreDbContext context = application.ApplicationServices.
                                         CreateScope().ServiceProvider.GetRequiredService <BookstoreDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.Books.Any())
            {
                context.Books.AddRange(
                    new Book
                {
                    Title          = "Les Miserables",
                    Author         = "Victor Hugo",
                    Publisher      = "Signet",
                    ISBN           = "978-0451419439",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 9.95f,
                    Pages          = 1488
                },
                    new Book
                {
                    Title          = "Team of Rivals",
                    Author         = "Doris Kearns Goodwin",
                    Publisher      = "Simon & Schuster",
                    ISBN           = "978-0743270755",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 14.58f,
                    Pages          = 944
                },
                    new Book
                {
                    Title          = "The Snowball",
                    Author         = "Alice Schroeder",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553384611",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 21.54f,
                    Pages          = 832
                },
                    new Book
                {
                    Title          = "American Ulysses",
                    Author         = "Ronald C. White",
                    Publisher      = "Random House",
                    ISBN           = "978-0812981254",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 11.61f,
                    Pages          = 864
                },
                    new Book
                {
                    Title          = "Unbroken",
                    Author         = "Laura Hillenbrand",
                    Publisher      = "Random House",
                    ISBN           = "978-0812974492",
                    Classification = "Non-Fiction",
                    Category       = "Historical",
                    Price          = 13.33f,
                    Pages          = 528
                },
                    new Book
                {
                    Title          = "The Great Train Robbery",
                    Author         = "Michael Crichton",
                    Publisher      = "Vintage",
                    ISBN           = "978-0804171281",
                    Classification = "Fiction",
                    Category       = "Historical Fiction",
                    Price          = 15.95f,
                    Pages          = 288
                },
                    new Book
                {
                    Title          = "Deep Work",
                    Author         = "Cal Newport",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455586691",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 14.99f,
                    Pages          = 304
                },
                    new Book
                {
                    Title          = "It's Your Ship",
                    Author         = "Michael Abrashoff",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455523023",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 21.66f,
                    Pages          = 240
                },
                    new Book
                {
                    Title          = "The Virgin Way",
                    Author         = "Richard Branson",
                    Publisher      = "Portfolio",
                    ISBN           = "978-1591847984",
                    Classification = "Non-Fiction",
                    Category       = "Business",
                    Price          = 29.16f,
                    Pages          = 400
                },
                    new Book
                {
                    Title          = "Sycamore Row",
                    Author         = "John Grisham",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553393613",
                    Classification = "Fiction",
                    Category       = "Thrillers",
                    Price          = 15.03f,
                    Pages          = 642
                },
                    new Book
                {
                    Title          = "As a Man Thinketh",
                    Author         = "James Allen",
                    Publisher      = "CreateSpace Independent Publishing Platform",
                    ISBN           = "978-1503055360",
                    Classification = "Motivational",
                    Category       = "Self-Help",
                    Price          = 5.99f,
                    Pages          = 38
                },
                    new Book
                {
                    Title          = "Mistborn: The Final Empire",
                    Author         = "Brandon Sanderson",
                    Publisher      = "Tor Teen",
                    ISBN           = "978-0765377135",
                    Classification = "Fantasy",
                    Category       = "Young-Adult",
                    Price          = 12.56f,
                    Pages          = 672
                },
                    new Book
                {
                    Title          = "Don Quixote",
                    Author         = "Miguel De Cervantes",
                    Publisher      = "Ecco",
                    ISBN           = "978-0060934347",
                    Classification = "Classic",
                    Category       = "Fiction",
                    Price          = 12.56f,
                    Pages          = 992
                }

                    );
                context.SaveChanges();
            }
            ;
        }
Example #3
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BookstoreDbContext context = application.ApplicationServices.
                                         CreateScope().ServiceProvider.GetRequiredService <BookstoreDbContext>();

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

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

                    new Book
                {
                    Title     = "Les Miserables",
                    Author    = "Victor Hugo",
                    Publisher = "Signet",
                    ISBN      = "978-0451419439",
                    Category  = "Fiction, Classic",
                    Price     = 9.95
                },

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

                    new Book
                {
                    Title     = "The Snowball",
                    Author    = "Alice Schroeder",
                    Publisher = "Bantam",
                    ISBN      = "978-0553384611",
                    Category  = "Non-Fiction, Biography",
                    Price     = 21.54
                },

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

                    new Book
                {
                    Title     = "Unbroken",
                    Author    = "Laura Hillenbrand",
                    Publisher = "Random House",
                    ISBN      = "978-0812974492",
                    Category  = "Non-Fiction, Historical",
                    Price     = 13.33
                },

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

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

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

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

                    new Book
                {
                    Title     = "Sycamore Row",
                    Author    = "John Grisham",
                    Publisher = "Bantam",
                    ISBN      = "978-0553393613",
                    Category  = "Fiction, Thrillers",
                    Price     = 15.03
                }



                    );

                context.SaveChanges();
            }
        }
Example #4
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BookstoreDbContext context = application.ApplicationServices.
                                         CreateScope().ServiceProvider.GetRequiredService <BookstoreDbContext>();

            //Checks if pending migrations
            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            //Creates database with these items
            if (!context.Books.Any())
            {
                context.Books.AddRange(

                    new Book
                {
                    Title          = "Les Miserables",
                    AuthFirstName  = "Victor",
                    AuthLastName   = "Hugo",
                    Publisher      = "Signet",
                    ISBN           = "978-0451419439",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 9.95,
                    NumPages       = 1488
                },

                    new Book
                {
                    Title          = "Team of Rivals",
                    AuthFirstName  = "Doris Kearns",
                    AuthLastName   = "Goodwin",
                    Publisher      = "Simon & Schuster",
                    ISBN           = "978-0743270755",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 14.58,
                    NumPages       = 944
                },

                    new Book
                {
                    Title          = "The Snowball",
                    AuthFirstName  = "Alice",
                    AuthLastName   = "Schroeder",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553384611",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 21.54,
                    NumPages       = 832
                },

                    new Book
                {
                    Title          = "American Ulysses",
                    AuthFirstName  = "Ronald C.",
                    AuthLastName   = "White",
                    Publisher      = "Random House",
                    ISBN           = "978-0812981254",
                    Classification = "Non-Fiction",
                    Category       = "Biography",
                    Price          = 11.61,
                    NumPages       = 864
                },

                    new Book
                {
                    Title          = "Unbroken",
                    AuthFirstName  = "Laura",
                    AuthLastName   = "Hillenbrand",
                    Publisher      = "Random House",
                    ISBN           = "978-0812974492",
                    Classification = "Non-Fiction",
                    Category       = "Historical",
                    Price          = 13.33,
                    NumPages       = 528
                },

                    new Book
                {
                    Title          = "The Great Train Robbery",
                    AuthFirstName  = "Michael",
                    AuthLastName   = "Crichton",
                    Publisher      = "Vintage",
                    ISBN           = "978-0804171281",
                    Classification = "Fiction",
                    Category       = "Historical Fiction",
                    Price          = 15.95,
                    NumPages       = 288
                },

                    new Book
                {
                    Title          = "Deep Work",
                    AuthFirstName  = "Cal",
                    AuthLastName   = "Newport",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455586691",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 14.99,
                    NumPages       = 304
                },

                    new Book
                {
                    Title          = "It's Your Ship",
                    AuthFirstName  = "Michael",
                    AuthLastName   = "Abrashoff",
                    Publisher      = "Grand Central Publishing",
                    ISBN           = "978-1455523023",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 21.66,
                    NumPages       = 240
                },

                    new Book
                {
                    Title          = "The Virgin Way",
                    AuthFirstName  = "Richard",
                    AuthLastName   = "Branson",
                    Publisher      = "Portfolio",
                    ISBN           = "978-1591847984",
                    Classification = "Non-Fiction",
                    Category       = "Business",
                    Price          = 29.16,
                    NumPages       = 400
                },

                    new Book
                {
                    Title          = "Sycamore Row",
                    AuthFirstName  = "John",
                    AuthLastName   = "Grisham",
                    Publisher      = "Bantam",
                    ISBN           = "978-0553393613",
                    Classification = "Fiction",
                    Category       = "Thrillers",
                    Price          = 15.03,
                    NumPages       = 642
                },

                    new Book
                {
                    Title          = "The Count of Monte Cristo",
                    AuthFirstName  = "Alexandre",
                    AuthLastName   = "Dumas",
                    Publisher      = "Penguin Classics",
                    ISBN           = "978-0140449266",
                    Classification = "Fiction",
                    Category       = "Classic",
                    Price          = 14.40,
                    NumPages       = 1276
                },

                    new Book
                {
                    Title          = "The Way of Kings",
                    AuthFirstName  = "Brandon",
                    AuthLastName   = "Sanderson",
                    Publisher      = "Tor Fantasy",
                    ISBN           = "978-0765365279",
                    Classification = "Fiction",
                    Category       = "Fantasy",
                    Price          = 9.59,
                    NumPages       = 1280
                },

                    new Book
                {
                    Title          = "Essentialism",
                    AuthFirstName  = "Greg",
                    AuthLastName   = "McKeown",
                    Publisher      = "Crown",
                    ISBN           = "978-0804137409",
                    Classification = "Non-Fiction",
                    Category       = "Self-Help",
                    Price          = 13.43,
                    NumPages       = 288
                }



                    );

                //Saves changes to the database
                context.SaveChanges();
            }
        }
Example #5
0
        //Method for checking for migrations and adding data to empty database
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BookstoreDbContext context = application.ApplicationServices.CreateScope().ServiceProvider.
                                         GetRequiredService <BookstoreDbContext>();

            //Migrate if migrations are needed
            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            //If there are no books in the database, create new book instances to add
            if (!context.Books.Any())
            {
                context.Books.AddRange
                (
                    new Book
                {
                    //Because BookId was specified as a key, it will be autogenerated when the object is created
                    //BookId = 1,
                    Title           = "Les Miserables",
                    AuthorFirstName = "Victor",
                    AuthorLastName  = "Hugo",
                    Publisher       = "Signet",
                    ISBN            = "978-0451419439",
                    Classification  = "Fiction",
                    Category        = "Classic",
                    Price           = 9.95,
                    PageCount       = 1488
                },
                    new Book
                {
                    Title            = "Team of Rivals",
                    AuthorFirstName  = "Doris",
                    AuthorMiddleName = "Kearns",
                    AuthorLastName   = "Goodwin",
                    Publisher        = "Simon & Schuster",
                    ISBN             = "978-0743270755",
                    Classification   = "Non-Fiction",
                    Category         = "Biography",
                    Price            = 14.58,
                    PageCount        = 944
                },
                    new Book
                {
                    Title           = "The Snowball",
                    AuthorFirstName = "Alice",
                    AuthorLastName  = "Schroeder",
                    Publisher       = "Bantam",
                    ISBN            = "978-0553384611",
                    Classification  = "Non-Fiction",
                    Category        = "Biography",
                    Price           = 21.54,
                    PageCount       = 832
                },
                    new Book
                {
                    Title            = "American Ulysses",
                    AuthorFirstName  = "Ronald",
                    AuthorMiddleName = "C.",
                    AuthorLastName   = "White",
                    Publisher        = "Random House",
                    ISBN             = "978-0812981254",
                    Classification   = "Non-Fiction",
                    Category         = "Biography",
                    Price            = 11.61,
                    PageCount        = 864
                },
                    new Book
                {
                    Title           = "Unbroken",
                    AuthorFirstName = "Laura",
                    AuthorLastName  = "Hillenbrand",
                    Publisher       = "Random House",
                    ISBN            = "978-0812974492",
                    Classification  = "Non-Fiction",
                    Category        = "Historical",
                    Price           = 13.33,
                    PageCount       = 528
                },
                    new Book
                {
                    Title           = "The Great Train Robbery",
                    AuthorFirstName = "Michael",
                    AuthorLastName  = "Crichton",
                    Publisher       = "Vintage",
                    ISBN            = "978-0804171281",
                    Classification  = "Fiction",
                    Category        = "Historical Fiction",
                    Price           = 15.95,
                    PageCount       = 288
                },
                    new Book
                {
                    Title           = "Deep Work",
                    AuthorFirstName = "Cal",
                    AuthorLastName  = "Newport",
                    Publisher       = "Grand Central Publishing",
                    ISBN            = "978-1455586691",
                    Classification  = "Non-Fiction",
                    Category        = "Self-Help",
                    Price           = 14.99,
                    PageCount       = 304
                },
                    new Book
                {
                    Title           = "It's Your Ship",
                    AuthorFirstName = "Michael",
                    AuthorLastName  = "Abrashoff",
                    Publisher       = "Grand Central Publishing",
                    ISBN            = "978-1455523023",
                    Classification  = "Non-Fiction",
                    Category        = "Self-Help",
                    Price           = 21.66,
                    PageCount       = 240
                },
                    new Book
                {
                    Title           = "The Virgin Way",
                    AuthorFirstName = "Richard",
                    AuthorLastName  = "Branson",
                    Publisher       = "Portfolio",
                    ISBN            = "978-1591847984",
                    Classification  = "Non-Fiction",
                    Category        = "Business",
                    Price           = 29.16,
                    PageCount       = 400
                },
                    new Book
                {
                    Title           = "Sycamore Row",
                    AuthorFirstName = "John",
                    AuthorLastName  = "Grisham",
                    Publisher       = "Bantam",
                    ISBN            = "978-0553393613",
                    Classification  = "Fiction",
                    Category        = "Thriller",
                    Price           = 15.03,
                    PageCount       = 642
                },

                    //New Books added after implementing pagination
                    //Required rerunning migrations and updating the database
                    new Book
                {
                    Title           = "The Way of Kings",
                    AuthorFirstName = "Brandon",
                    AuthorLastName  = "Sanderson",
                    Publisher       = "Tor Fantasy",
                    ISBN            = "978-0765365279",
                    Classification  = "Fiction",
                    Category        = "Fantasy",
                    Price           = 9.59,
                    PageCount       = 1280
                },
                    new Book
                {
                    Title           = "All Systems Red",
                    AuthorFirstName = "Martha",
                    AuthorLastName  = "Wells",
                    Publisher       = "Tor",
                    ISBN            = "978-0765397539",
                    Classification  = "Science Fiction",
                    Category        = "Fantasy",
                    Price           = 13.39,
                    PageCount       = 160
                },
                    new Book
                {
                    Title           = "20,000 Leagues Under the Sea",
                    AuthorFirstName = "Jules",
                    AuthorLastName  = "Verne",
                    Publisher       = "Wordsworth Editions Ltd",
                    ISBN            = "978-1853260315",
                    Classification  = "Science Fiction",
                    Category        = "Classic",
                    Price           = 3.95,
                    PageCount       = 256
                }
                );

                context.SaveChanges();
            }
        }
Example #6
0
        //Ensure data is provided for database
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BookstoreDbContext context = application.ApplicationServices.
                                         CreateScope().ServiceProvider.GetRequiredService <BookstoreDbContext>();

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

            //Add starting data
            if (!context.Books.Any())
            {
                context.Books.AddRange(
                    new Book
                {
                    Title           = "Les Miserables",
                    AuthorFirstName = "Victor",
                    AuthorLastName  = "Hugo",
                    Publisher       = "Signet",
                    ISBN            = "978-0451419439",
                    Classification  = "Fiction",
                    Category        = "Classic",
                    Price           = 9.95,
                    NumberOfPages   = 1488
                },

                    new Book
                {
                    Title            = "Team of Rivals",
                    AuthorFirstName  = "Doris",
                    AuthorLastName   = "Goodwin",
                    AuthorMiddleName = "Kearns",
                    Publisher        = "Simon & Schuster",
                    ISBN             = "978-0743270755",
                    Classification   = "Non-Fiction",
                    Category         = "Biography",
                    Price            = 14.58,
                    NumberOfPages    = 944
                },

                    new Book
                {
                    Title           = "The Great Train Robbery",
                    AuthorFirstName = "Michael",
                    AuthorLastName  = "Crighton",
                    Publisher       = "Vintage",
                    ISBN            = "978-0804171281",
                    Classification  = "Fiction",
                    Category        = "Historical Fiction",
                    Price           = 15.95,
                    NumberOfPages   = 288
                },

                    new Book
                {
                    Title           = "The Virgin Way",
                    AuthorFirstName = "Richard",
                    AuthorLastName  = "Branson",
                    Publisher       = "Portfolio",
                    ISBN            = "978-1591847984",
                    Classification  = "Non-Fiction",
                    Category        = "Business",
                    Price           = 29.16,
                    NumberOfPages   = 400
                },

                    new Book
                {
                    Title           = "Sycamore Row",
                    AuthorFirstName = "John",
                    AuthorLastName  = "Grisham",
                    Publisher       = "Bantam",
                    ISBN            = "978-0553393613",
                    Classification  = "Fiction",
                    Category        = "Thrillers",
                    Price           = 15.03,
                    NumberOfPages   = 642
                },

                    new Book
                {
                    Title           = "The Snowball",
                    AuthorFirstName = "Alice",
                    AuthorLastName  = "Schroeder",
                    Publisher       = "Bantam",
                    ISBN            = "978-0553384611",
                    Classification  = "Non-Fiction",
                    Category        = "Biography",
                    Price           = 21.54,
                    NumberOfPages   = 832
                },

                    new Book
                {
                    Title            = "American Ulysses",
                    AuthorFirstName  = "Ronald",
                    AuthorLastName   = "White",
                    AuthorMiddleName = "C.",
                    Publisher        = "Random House",
                    ISBN             = "978-0812981254",
                    Classification   = "Non-Fiction",
                    Category         = "Biography",
                    Price            = 11.61,
                    NumberOfPages    = 864
                },

                    new Book
                {
                    Title           = "Unbroken",
                    AuthorFirstName = "Laura",
                    AuthorLastName  = "Hillenbrand",
                    Publisher       = "Random House",
                    ISBN            = "978-0812974492",
                    Classification  = "Non-Fiction",
                    Category        = "Historical",
                    Price           = 13.33,
                    NumberOfPages   = 528
                },

                    new Book
                {
                    Title           = "Deep Work",
                    AuthorFirstName = "Cal",
                    AuthorLastName  = "Newport",
                    Publisher       = "Grand Central Publishing",
                    ISBN            = "978-1455586691",
                    Classification  = "Non-Fiction",
                    Category        = "Self-Help",
                    Price           = 14.99,
                    NumberOfPages   = 304
                },

                    new Book
                {
                    Title           = "It's Your Ship",
                    AuthorFirstName = "Michael",
                    AuthorLastName  = "Abrashoff",
                    Publisher       = "Grand Central Publishing",
                    ISBN            = "978-1455523023",
                    Classification  = "Non-Fiction",
                    Category        = "Self-Help",
                    Price           = 21.66,
                    NumberOfPages   = 240
                },

                    new Book
                {
                    Title           = "Harry Potter and the Chamber of Secrets",
                    AuthorFirstName = "JK",
                    AuthorLastName  = "Rowling",
                    Publisher       = "Scholastic",
                    ISBN            = "978-1455523028",
                    Classification  = "Fiction",
                    Category        = "Fantasy",
                    Price           = 15.00,
                    NumberOfPages   = 341
                },

                    new Book
                {
                    Title           = "Harry Potter and the Prisoner of Azkaban",
                    AuthorFirstName = "JK",
                    AuthorLastName  = "Rowling",
                    Publisher       = "Scholastic",
                    ISBN            = "978-1455523029",
                    Classification  = "Fiction",
                    Category        = "Fantasy",
                    Price           = 15.00,
                    NumberOfPages   = 435
                },

                    new Book
                {
                    Title           = "Harry Potter and the Goblet of Fire",
                    AuthorFirstName = "JK",
                    AuthorLastName  = "Rowling",
                    Publisher       = "Scholastic",
                    ISBN            = "978-1455523027",
                    Classification  = "Fiction",
                    Category        = "Fantasy",
                    Price           = 15.00,
                    NumberOfPages   = 734
                }
                    );

                context.SaveChanges();
            }
        }