Esempio n. 1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            Configuration = builder.Build();

            var serviceCollection = new ServiceCollection();

            ConfigureServices(serviceCollection);

            ServiceProvider = serviceCollection.BuildServiceProvider();

            var dbOptions = ServiceProvider.GetService <DbContextOptions <BooksDBContext> >();

            using (var context = new BooksDBContext(dbOptions))
            {
                context.Database.EnsureCreated();
            }


            var mainWindow = ServiceProvider.GetRequiredService <MainWindow>();

            mainWindow.Show();
        }
        public IEnumerable <Book> Get(int pageNum)
        {
            int pageSize      = 4;
            int startPosition = (pageNum - 1) * pageSize;

            using (var context = new BooksDBContext())
            {
                List <Book> books = context.Books.ToList();
                if (books.Count >= startPosition)
                {
                    return(books.Skip(startPosition).Take(pageSize));
                }
                else
                {
                    return(new List <Book>());
                }
            }
        }
 public HomeController(BooksDBContext db)
 {
     context = db;
 }
 public BooksController(BooksDBContext context)
 {
     _context = context;
 }
Esempio n. 5
0
 public BookService(BooksDBContext db)
 {
     _db = db;
 }
Esempio n. 6
0
 public BooksController(BooksDBContext _myDBContext)
 {
     myDBContext = _myDBContext;
     //myDBContext = new MyDBContext();//不需要 不然得传参数op
 }
 public InscriptionsController(BooksDBContext context)
 {
     _context = context;
 }
 public AuthorsController(BooksDBContext context)
 {
     _context = context;
 }
 public BooksController(BooksDBContext booksDBContext)
 {
     _BooksDBContext = booksDBContext;
 }