Esempio n. 1
0
        // This method will create and seed the database.
        public static void Initialize(HotelBookingContext context)
        {
            // Delete the database, if it already exists. I do this because an
            // existing database may not be compatible with the entity model,
            // if the entity model was changed since the database was created.
            context.Database.EnsureDeleted();

            // Create the database, if it does not already exists. This operation
            // is necessary, if you use an SQL Server database.
            context.Database.EnsureCreated();

            // Look for any bookings.
            if (context.Booking.Any())
            {
                return;   // DB has been seeded
            }

            List <Customer> customers = new List <Customer>
            {
                new Customer {
                    Name = "John Smith", Email = "*****@*****.**"
                },
                new Customer {
                    Name = "Jane Doe", Email = "*****@*****.**"
                }
            };

            List <Room> rooms = new List <Room>
            {
                new Room {
                    Description = "A"
                },
                new Room {
                    Description = "B"
                },
                new Room {
                    Description = "C"
                }
            };

            DateTime       date     = DateTime.Today.AddDays(4);
            List <Booking> bookings = new List <Booking>
            {
                new Booking {
                    StartDate = date, EndDate = date.AddDays(14), IsActive = true, CustomerId = 1, RoomId = 1
                },
                new Booking {
                    StartDate = date, EndDate = date.AddDays(14), IsActive = true, CustomerId = 2, RoomId = 2
                },
                new Booking {
                    StartDate = date, EndDate = date.AddDays(14), IsActive = true, CustomerId = 1, RoomId = 3
                }
            };

            context.Customer.AddRange(customers);
            context.Room.AddRange(rooms);
            context.SaveChanges();
            context.Booking.AddRange(bookings);
            context.SaveChanges();
        }
        public HotelBookingContextFactory()
        {
            var options = new DbContextOptionsBuilder <HotelBookingContext>()
                          .UseInMemoryDatabase("HotelBookingDb")
                          .Options;

            Context = new HotelBookingContext(options);
        }
Esempio n. 3
0
 public EditModel(HotelBooking.Data.HotelBookingContext context)
 {
     _context = context;
 }
Esempio n. 4
0
 public DeleteModel(HotelBooking.Data.HotelBookingContext context)
 {
     _context = context;
 }
 public DetailsModel(HotelBooking.Data.HotelBookingContext context)
 {
     _context = context;
 }
Esempio n. 6
0
 public IndexModel(HotelBooking.Data.HotelBookingContext context)
 {
     _context = context;
 }