public object GetService(Type serviceType) { if (serviceType == typeof(FlightsController)) { return(new FlightsController(new FlightRepository(), new LocationRepository())); } if (serviceType == typeof(LocationsController)) { return(new LocationsController(new LocationRepository())); } if (serviceType == typeof(ReservationsController)) { return(new ReservationsController(new ReservationRepository())); } if (serviceType == typeof(TravelersController)) { var dbContext = new TravelCompanionContext(); return(new TravelersController(new TravelerRepository(dbContext), new ReservationRepository(dbContext), new FlightRepository(dbContext), new LocationRepository(dbContext))); } if (serviceType == typeof(TripsController)) { return(new TripsController(new ReservationRepository())); } if (serviceType == typeof(FrequentFlyersController)) { return(new FrequentFlyersController()); } if (serviceType == typeof(FilesController)) { return(new FilesController(new ReservationRepository())); } return(null); }
public Location Get(int id) { Location location = null; // TODO: Place cache initialization here DataCacheFactory cacheFactory = new DataCacheFactory(); DataCache cache = cacheFactory.GetDefaultCache(); // TODO: Find the location entity in the cache string cacheKey = "location_" + id.ToString(); location = cache.Get(cacheKey) as Location; if (location == null) { using (TravelCompanionContext context = new TravelCompanionContext()) { var locations = from l in context.Locations where l.LocationId == id select l; location = locations.FirstOrDefault(); // TODO: Add the location to the cache cache.Put(cacheKey, location); } } return(location); }
public void Dispose() { if (context != null) { context.Dispose(); context = null; } }
public void Dispose() { //TODO :Lab 02 Exercise 1, Task 4.4 : Implement the Dispose Method if (context != null) { context.Dispose(); context = null; } }
public void Dispose() { if (context != null) { context.Dispose(); context = null; } GC.SuppressFinalize(this); }
protected void Application_Start() { TravelCompanionContext context = new TravelCompanionContext(); //context.Database.Log = s => System.Diagnostics.Debug.Write(s); (new FlightScheduleDatabaseInitializer()).InitializeDatabase(context); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); }
protected void Application_Start() { using (var db = new TravelCompanionContext()) { Database.SetInitializer(new FlightScheduleDatabaseInitializer()); db.Database.Initialize(true); } AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); }
public void GetOrderedReservations() { List <Reservation> reservations = null; using (TravelCompanionContext context = new TravelCompanionContext()) { //TODO: Lab 02 Exercise 2, Task 3.1 : Create an Entity SQL Query Assert.AreEqual(reservations.Count, 2); Assert.AreEqual(reservations.ElementAt(0).ConfirmationCode, "4321"); Assert.AreEqual(reservations.ElementAt(1).ConfirmationCode, "1234"); } }
public void GetReservationsForDepartFlightsBySeatClass() { using (TravelCompanionContext context = new TravelCompanionContext()) { IEnumerable <Reservation> query = context.Database.SqlQuery <Reservation>( @"select r.* from Reservations r inner join Trips t on r.DepartFlightScheduleID = t.TripId where t.Class = 2"); List <Reservation> flights = query.ToList(); Assert.AreEqual(flights.Count, 1); Assert.AreEqual(flights[0].ConfirmationCode, "1234"); } }
private List <ReservationDTO> GetLatestReservations(int latest) { using (var context = new TravelCompanionContext()) { return((from reservation in context.Reservations orderby reservation.ReservationDate descending select new ReservationDTO { Source = reservation.DepartureFlight.FlightInfo.Flight.Source.City, Destination = reservation.DepartureFlight.FlightInfo.Flight.Destination.City, DepartureDate = reservation.DepartureFlight.FlightInfo.Departure, Confirmation = reservation.ConfirmationCode, ReservationDate = reservation.ReservationDate }).Take(latest).ToList()); } }
public void GetOrderedReservations() { List <Reservation> reservations = null; using (TravelCompanionContext context = new TravelCompanionContext()) { //TODO: Lab 02 Exercise 2, Task 3.1 : Create an Entity SQL Query var sql = @"SELECT value r FROM reservations as r ORDER BY r.confirmationCode DESC"; ObjectQuery <Reservation> query = ((IObjectContextAdapter)context).ObjectContext.CreateQuery <Reservation>(sql); reservations = query.ToList(); Assert.AreEqual(reservations.Count, 2); Assert.AreEqual(reservations.ElementAt(0).ConfirmationCode, "4321"); Assert.AreEqual(reservations.ElementAt(1).ConfirmationCode, "1234"); } }
public void GetFlightSchedulesByLocation() { using (TravelCompanionContext context = new TravelCompanionContext()) { IEnumerable <FlightSchedule> flights = context.Database.SqlQuery <FlightSchedule>( @"Select fs.* from Flights fr inner join Locations l on fr.destination_LocationId = l.locationId inner join FlightSchedules fs on fr.flightId = fs.flightId where l.city = 'Paris'"); Assert.AreEqual(flights.Count(), 2); } }
public void GetOrderedFilteredLocations() { using (TravelCompanionContext context = new TravelCompanionContext()) { ObjectQuery <Location> query = ((IObjectContextAdapter)context).ObjectContext.CreateQuery <Location>( @"SELECT value l FROM locations as l WHERE l.state is null ORDER BY l.city"); List <Location> locations = query.ToList(); Assert.AreEqual(locations.Count, 2); Assert.AreEqual(locations.ElementAt(0).City, "Paris"); Assert.AreEqual(locations.ElementAt(1).City, "Rome"); } }
public void GetReservationsWithSingleFlightWithoutLazyLoad() { Reservation reservation; TravelCompanionContext context = new TravelCompanionContext(); //TODO: Lab 02 Exercise 2, Task 2.3 : Turn Lazy Loading Off using (var repository = new ReservationRepository(context)) { var query = from r in repository.GetAll() where r.ConfirmationCode == "1234" select r; reservation = query.FirstOrDefault(); Assert.IsNotNull(reservation); Assert.IsNull(reservation.DepartureFlight); Assert.IsNull(reservation.ReturnFlight); } }
public HttpResponseMessage Post([FromUri] string traveler) { using (var context = new TravelCompanionContext()) { Traveler newTraveler = new Traveler { FirstName = traveler, LastName = "Mc" + traveler, HomeAddress = "One Microsoft Way", MobilePhone = "555-555-5555", Passport = "AB123456789", TravelerUserIdentity = Guid.NewGuid().ToString() }; context.Travelers.Add(newTraveler); context.SaveChanges(); Flight flight = context.Flights.First(); Reservation reservation = new Reservation { ReservationDate = DateTime.Now, DepartureFlight = new Trip { FlightInfo = flight.Schedules.First(), Status = FlightStatus.Confirmed, Class = SeatClass.Economy }, ReturnFlight = null, ConfirmationCode = Guid.NewGuid().ToString(), TravelerId = newTraveler.TravelerId }; context.Reservations.Add(reservation); context.SaveChanges(); } // TODO: Lab 12, Exercise 1, Task 1.4 : Delete the cached results from Redis RedisProvider.Cache.KeyDelete(RESERVATIONS_KEY); return(Request.CreateResponse(HttpStatusCode.Created)); }
public Location Get(int id) { Location location = null; // TODO: Place cache initialization here // TODO: Find the location entity in the cache if (location == null) { using (TravelCompanionContext context = new TravelCompanionContext()) { var locations = from l in context.Locations where l.LocationId == id select l; location = locations.FirstOrDefault(); // TODO: Add the location to the cache } } return(location); }
public FlightRepository(string connectionName) { context = new TravelCompanionContext(connectionName); }
public LocationRepository(TravelCompanionContext dbContext) { context = dbContext; }
public LocationRepository() { context = new TravelCompanionContext(); }
public ReservationRepository(string connectionName) { context = new TravelCompanionContext(connectionName); }
public FlightRepository(TravelCompanionContext dbContext) { context = dbContext; }
public TravelerRepository(TravelCompanionContext dbContext) { context = dbContext; }
public FlightRepository() { context = new TravelCompanionContext(); }
public TravelerRepository() { context = new TravelCompanionContext(); }