public ReservationApiDbContext InitializeDatabase(string databaseName) { var options = new DbContextOptionsBuilder <ReservationApiDbContext>().UseInMemoryDatabase(databaseName).Options; var context = new ReservationApiDbContext(options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); IEnumerable <FlightRequest> results; //TODO - Read the seed data fileName from the Settings files -> appsettings.json using (StreamReader r = new StreamReader(@".\..\..\..\..\..\InitialState.json")) { string json = r.ReadToEnd(); results = JsonConvert.DeserializeObject <IEnumerable <FlightRequest> >(json); foreach (var item in results) { FlightEntity flight = new FlightEntity { FlightKey = item.key, Origin = item.origin, Destination = item.destination, Time = item.time, }; context.Flights.Add(flight); } } context.SaveChanges(); return(context); }
public FlightService( ReservationApiDbContext context, IMapper mapper, IOptions <MySettings> configuration) { _context = context; _mapper = mapper; _configuration = configuration; }
public ReservationService( ReservationApiDbContext context, IMapper mapper, ReservationNumberService reservationNumber, IConfiguration configuration) { _context = context; _mapper = mapper; _reservationNumber = reservationNumber; _configuration = configuration; }