public BookTradeRepository(BookTradeContext context) { _context = context; }
public static void EnsureSeedDataForContext(this BookTradeContext context) { if (context.Schools.Any()) { return; } var schools = new List <School>() { new School() { Name = "California State University Northridge", Website = "csun.edu", Users = new List <User>() { new User() { Username = "******", Firstname = "Guy", Lastname = "Person", Email = "*****@*****.**", SchoolId = 1, Profile = "I am a real person please trade all your books with me", StudentIdentification = "213182235", Password = "******", Books = new List <Book>() { new Book() { Name = "Introduction to Algorithms", Edition = "3rd", Author = "Thomas M, Cormen", ISBN13 = "978-0262033848", ISBN10 = "9780262033848", Price = 30, Condition = "Poor", Notes = "I used it as a coaster for 3 years take it away from me." }, new Book() { Name = " Data Structures", Edition = "12th", Author = "Koffman, Eliot", ISBN13 = "978-1119186540", ISBN10 = "1119186540", Price = 25, Condition = "Poor", Notes = " Still readable. Few missing pages. " } } }, new User() { Username = "******", Firstname = "Jason", Lastname = "Ray", Email = "*****@*****.**", SchoolId = 1, Profile = "Computer Science major, Junior", StudentIdentification = "123345687", Password = "******", Books = new List <Book>() { new Book() { Name = " Introduction to Algorithms", Edition = "3rd", Author = "Thomas M, Cormen", ISBN13 = "978-0262033848", ISBN10 = "0262033848", Price = 60, Condition = "Great", Notes = " Great Condition.Good care. " }, new Book() { Name = " Calculus", Edition = "8th", Author = "Stewart, James", ISBN13 = "978-1285740621", ISBN10 = "1285740621", Price = 80, Condition = "Poor", Notes = " 3 years old. Worn out a bit still useful. " }, new Book() { Name = " Data Structures", Edition = "12th", Author = "Koffman, Eliot", ISBN13 = "978-1119186540", ISBN10 = "1119186540", Price = 50, Condition = "Good", Notes = " Practically new. " } } }, new User() { Username = "******", Firstname = "Maria", Lastname = "Lopez", Email = "*****@*****.**", SchoolId = 1, Profile = "BIOLOGY major ! Allbooks ready to go!", StudentIdentification = "134526987", Password = "******", Books = new List <Book>() { new Book() { Name = " Calculus", Edition = "8th", Author = "Stewart, James", ISBN13 = "978-1285740621", ISBN10 = "1285740621", Price = 80, Condition = "New", Notes = " Used for one semester only. " }, new Book() { Name = " Biology", Edition = "12th", Author = "Mader, Sylvia", ISBN13 = "978-0078024269", ISBN10 = "0078024269", Price = 100, Condition = "New", Notes = " Just used it one semester before calling quits. Take it away. " } } }, new User() { Username = "******", Firstname = "Raymond", Lastname = "Sanchez", Email = "*****@*****.**", SchoolId = 1, Profile = "Electrical engeneering! all books for all 4 years ", StudentIdentification = "154562589", Password = "******", Books = new List <Book>() { new Book() { Name = " Introduction to Algorithms", Edition = "3rd", Author = "Thomas M, Cormen", ISBN13 = "978-0262033848", ISBN10 = "0262033848", Price = 45, Condition = "Good", Notes = " Just bought it last semester. Still good condition. " }, new Book() { Name = " Calculus", Edition = "8th", Author = "Stewart, James", ISBN13 = "978-1285740621", ISBN10 = "1285740621", Price = 40, Condition = "Good", Notes = " Some higlighted pages. Still readable. " }, new Book() { Name = " Biology", Edition = "12th", Author = "Mader, Sylvia", ISBN13 = "978-0078024269", ISBN10 = "0078024269", Price = 50, Condition = "Good", Notes = " Couple of highlighted pictures. " } } }, new User() { Username = "******", Firstname = "Joy", Lastname = "Mercedez", Email = "*****@*****.**", SchoolId = 1, Profile = "Performing arts major , Senior", StudentIdentification = "165897435", Password = "******", Books = new List <Book>() { new Book() { Name = " Calculus", Edition = "8th", Author = "Stewart, James", ISBN13 = "978-1285740621", ISBN10 = "1285740621", Price = 80, Condition = "New", Notes = " Used for one semester only. " } } }, new User() { Username = "******", Firstname = "Bryan", Lastname = "Yang", Email = "*****@*****.**", SchoolId = 1, Profile = "Health and Science major", StudentIdentification = "156587946", Password = "******", Books = new List <Book>() { new Book() { Name = " Introduction to Algorithms", Edition = "3rd", Author = "Thomas M, Cormen", ISBN13 = "978-0262033848", ISBN10 = "0262033848", Price = 80, Condition = "New", Notes = " Honestly never used it. Practically new. " } } } } } }; context.Schools.AddRange(schools); context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, BookTradeContext bookTradeContext) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v0.1/swagger.json", "Student Textbook Tradting Center API V0.1"); c.RoutePrefix = string.Empty; }); app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod() .AllowAnyHeader().AllowCredentials()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } bookTradeContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Entities.User, Models.UserDto>(); cfg.CreateMap <Entities.User, Models.UserWithoutBooksDto>(); cfg.CreateMap <Entities.Book, Models.BookDto>(); cfg.CreateMap <Entities.Book, Models.BookWithSellerDto>(); } ); app.UseMvc(); }