public void AddToShopingCart(Book book, int qty) { var shopingCartItem = _dbContext.ShopingCartItems.SingleOrDefault( s => s.Book.Id == book.Id && s.ShopingCartId == ShopingCartId); if (shopingCartItem == null) { shopingCartItem = new ShopingCartItem { ShopingCartId = ShopingCartId, Amount = qty, Book = book }; _dbContext.ShopingCartItems.Add(shopingCartItem); } else { shopingCartItem.Amount++; } _dbContext.SaveChanges(); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new BookStoreContext( serviceProvider.GetRequiredService < DbContextOptions <BookStoreContext> >())) { if (context.Book.Any()) { return; } context.Book.AddRange( new Book { Name = "Lord Of The Rings", Author = "J.R.R. Tolkien", Genre = "Adventure", Price = 10, Year = 1975 }, new Book { Name = "The Shining", Author = "Stephen King", Genre = "Horror", Price = 6, Year = 1988 }, new Book { Name = "Fahrenheit 451", Author = "Ray Bradbury", Year = 1968, Genre = "Dystopian", Price = 3 }, new Book { Name = "The Dark Tower", Author = "Stephen King", Genre = "Adventure", Price = 11, Year = 1999 } ); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new BookStoreContext( serviceProvider.GetRequiredService < DbContextOptions <BookStoreContext> >())) { // Look for any movies. if (context.Book.Any()) { return; // DB has been seeded } context.Book.AddRange( new Book { Title = "Anna Karenina", Date = DateTime.Parse("1877-2-12"), Author = "Leo Tolstoy", }, new Book { Title = "To Kill a Mockingbird", Date = DateTime.Parse("1960-6-11"), Author = "Harper Lee" }, new Book { Title = "The Great Gatsby", Date = DateTime.Parse("1925-4-10"), Author = "F. Scott Fitzgerald" }, new Book { Title = "One Hundred Years of Solitude", Date = DateTime.Parse("1967-5-15"), Author = "Gabriel García Márquez" }, new Book { Title = "Jane Eyre", Date = DateTime.Parse("1847-10-16"), Author = "Charlotte Brontë" } ); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new BookStoreContext( serviceProvider.GetRequiredService < DbContextOptions <BookStoreContext> >())) { // Look for any movies. if (context.Book.Any()) { return; // DB has been seeded } context.Book.AddRange( new Book { Author = "Diana Gabaldon", ISBN = "123456789", Name = "Outlander", PlotReview = @" Is the first in a series of eight historical multi-genre novels by Diana Gabaldon. Published in 1991, it focuses on the Second World War-era nurse Claire Randall, who travels through time to 18th century Scotland and finds adventure and romance with the dashing Jamie Fraser.[1] A mix of several genres, the Outlander series has elements of historical fiction, romance, adventure and science fiction/fantasy.", Type = "Cience Fiction" }, new Book { Author = "J. K. Rowling", ISBN = "23568974", Name = "Harry Potter", PlotReview = @"Is a series of fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic, and subjugate all wizards and Muggles (non-magical people).", Type = "Fantasy" }, new Book { Author = "Suzanne Collins", ISBN = "12562345", Name = "The Hunger Games", PlotReview = @"Is a 2008 dystopian novel by the American writer Suzanne Collins. It is written in the voice of 16-year-old Katniss Everdeen, who lives in the future, post-apocalyptic nation of Panem in North America. The Capitol, a highly advanced metropolis, exercises political control over the rest of the nation. The Hunger Games is an annual event in which one boy and one girl aged 12–18 from each of the twelve districts surrounding the Capitol are selected by lottery to compete in a televised Battle royal to the death.", Type = "Distopia" }, new Book { Author = "Stephen King", ISBN = "7894561230", Name = "The Dark Tower", PlotReview = @"It describes a ""gunslinger"" and his quest toward a tower, the nature of which is both physical and metaphorical. The series, and its use of the Dark Tower, expands upon Stephen King's multiverse and in doing so, links together many of his other novels. In addition to the eight novels of the series proper that comprise 4,250 pages, many of King's other books relate to the story, introducing concepts and characters that come into play as the series progresses.", Type = "Fantasy" }); context.SaveChanges(); } }
public static void EnsurePopulated(IApplicationBuilder application) { BookStoreContext context = application.ApplicationServices. CreateScope().ServiceProvider.GetRequiredService <BookStoreContext>(); if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } if (!context.Books.Any()) { context.Books.AddRange( new Book { Title = "Les Miserables", AuthorFirstName = "Victor", AuthorMiddleName = "", AuthorLastName = "Hugo", Publisher = "Signet", ISBN = "978-0451419439", Fiction = true, Category = "Classic", Price = 9.95, Pages = 1488 }, new Book { Title = "Team of Rivals", AuthorFirstName = "Doris", AuthorMiddleName = "Kearns", AuthorLastName = "Goodwin", Publisher = "Smin & Schuster", ISBN = "978-0743270755", Fiction = false, Category = "Biography", Price = 14.58, Pages = 944 }, new Book { Title = "The Snowball", AuthorFirstName = "Alice", AuthorMiddleName = "", AuthorLastName = "Schroeder", Publisher = "Bantam", ISBN = "978-0553384611", Fiction = false, Category = "Biography", Price = 21.54, Pages = 832 }, new Book { Title = "American Ulysses", AuthorFirstName = "Ronald", AuthorMiddleName = "C.", AuthorLastName = "White", Publisher = "Random House", ISBN = "978-0812981254", Fiction = false, Category = "Biography", Price = 11.61, Pages = 864 }, new Book { Title = "Unbroken", AuthorFirstName = "Laura", AuthorMiddleName = "", AuthorLastName = "Hillenbrand", Publisher = "Random House", ISBN = "978-0743270755", Fiction = false, Category = "Biography", Price = 13.33, Pages = 528 }, new Book { Title = "The Great Train Robbery", AuthorFirstName = "Michael", AuthorMiddleName = "", AuthorLastName = "Crichton", Publisher = "Vintage", ISBN = "978-0804171281", Fiction = true, Category = "Historical Fiction", Price = 15.95, Pages = 288 }, new Book { Title = "Deep Work", AuthorFirstName = "Cal", AuthorMiddleName = "", AuthorLastName = "Newport", Publisher = "Grand Central Publishing", ISBN = "978-1455586691", Fiction = false, Category = "Self-Help", Price = 14.99, Pages = 304 }, new Book { Title = "It's Your Ship", AuthorFirstName = "Cal", AuthorMiddleName = "", AuthorLastName = "Newport", Publisher = "Grand Publishing Station", ISBN = "978-1455523023", Fiction = false, Category = "Self-Help", Price = 21.66, Pages = 240 }, new Book { Title = "The Virgin Way", AuthorFirstName = "Richard", AuthorMiddleName = "", AuthorLastName = "Branson", Publisher = "Portfolio", ISBN = "978-1591847984", Fiction = false, Category = "Business", Price = 14.58, Pages = 400 }, new Book { Title = "Sycamore Row", AuthorFirstName = "Doris", AuthorMiddleName = "", AuthorLastName = "Kearns", Publisher = "Smin & Schuster", ISBN = "978-0743270755", Fiction = true, Category = "Thrillers", Price = 14.58, Pages = 944 }, new Book { Title = "The Lean Startup", AuthorFirstName = "Eric", AuthorMiddleName = "", AuthorLastName = "Ries", Publisher = "Crown Publishing Group", ISBN = "978-0307887898", Fiction = false, Category = "Business", Price = 14.50, Pages = 336 }, new Book { Title = "Moby Dick", AuthorFirstName = "Herman", AuthorMiddleName = "", AuthorLastName = "Melville", Publisher = "Richard Bently", ISBN = "978-80140861723", Fiction = true, Category = "Epic", Price = 12.13, Pages = 752 }, new Book { Title = "Don Quixote", AuthorFirstName = "Miguel", AuthorMiddleName = "de", AuthorLastName = "Cervantes", Publisher = "Penguin Classics", ISBN = "978-1400132171", Fiction = true, Category = "Satire", Price = 15.30, Pages = 863 } ); context.SaveChanges(); } }