using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using TestEnvironment.Models;

namespace TestEnvironment
{
        public class BookDbContext : DbContext
        {
            public BookDbContext(DbContextOptions<BookDbContext> dbContextOptions) : base(dbContextOptions)
            {
                try
                {
                    var databaseCreator = Database.GetService<IDatabaseCreator>() as RelationalDatabaseCreator;

                    if (databaseCreator != null)
                    {
                        if (!databaseCreator.CanConnect()) databaseCreator.Create();
                        if (!databaseCreator.HasTables()) databaseCreator.CreateTables();
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            public DbSet<Book> Book { get; set; }
            public DbSet<Review> Review { get; set; }
        }
 }


