public UnitOfWork(DbOptions opt) { DbContextOptions <HotelExamContext> options; Console.WriteLine(opt.Environment); // Connects to our in memory database if (opt.Environment == "Development") { options = new DbContextOptionsBuilder <HotelExamContext>() .UseInMemoryDatabase("InternalDb") .Options; } // Connects to our actual database else { options = new DbContextOptionsBuilder <HotelExamContext>() .UseSqlServer(opt.ConnectionString) .Options; } // Ensures that the database exsists context = new HotelExamContext(options); context.Database.EnsureCreated(); GuestRepository = new GuestRepository(context); AdminRepository = new AdminRepository(context); UserRepository = new UserRepository(context); BookingRepository = new BookingRepository(context); SingleRoomRepository = new SingleRoomRepository(context); DoubleRoomRepository = new DoubleRoomRepository(context); SuiteRepository = new SuiteRepository(context); }
// Makes the context available in the class public SuiteRepository(HotelExamContext context) { this.context = context; }
// Makes the context available in the class public UserRepository(HotelExamContext context) { this.context = context; }
// Makes the context available in the class public GuestRepository(HotelExamContext context) { this.context = context; }
// Makes the context available in the class public SingleRoomRepository(HotelExamContext context) { this.context = context; }
// Makes the context available in the class public BookingRepository(HotelExamContext context) { this.context = context; }
// Makes the context available in the class public AdminRepository(HotelExamContext context) { this.context = context; }