예제 #1
0
        public async Task <HttpResponseMessage> GetFlightById(string id)
        {
            Flight flight = await FlightRepository.GetFlight(new ObjectId(id));

            if (flight == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "Error, Flight couldn't find!"));
            }

            return(Request.CreateResponse <Flight>(HttpStatusCode.OK, flight));
        }
예제 #2
0
        public void InsertFlight()
        {
            FlightRepository   flightRepository;
            LocationRepository locationRepository;
            Location           from, to;

            string   flightNumber = "BY999";
            DateTime takeOff      = new DateTime(2014, 2, 1, 8, 30, 0); // Feb. 1st 2014, 8:30am

            using (locationRepository = new LocationRepository())
            {
                from = locationRepository.FindBy(l => l.City == "Paris").Single();
                to   = locationRepository.FindBy(l => l.City == "New-York").Single();
            }

            using (flightRepository = new FlightRepository())
            {
                Flight newFlight = new Flight();
                newFlight.FlightNumber = flightNumber;
                newFlight.Destination  = to;
                newFlight.Source       = from;
                newFlight.Schedules    = new List <FlightSchedule> {
                    new FlightSchedule
                    {
                        Departure = takeOff,
                        Duration  = new TimeSpan(2, 30, 0)
                    }
                };

                flightRepository.Add(newFlight);
                flightRepository.Save();
            }

            using (flightRepository = new FlightRepository())
            {
                Flight newFlight = flightRepository.GetFlight(flightNumber);
                Assert.AreEqual(newFlight.FlightNumber, flightNumber);
                Assert.AreEqual(newFlight.Destination.City, "New-York");
                Assert.AreEqual(newFlight.Source.City, "Paris");
                Assert.AreEqual(newFlight.Schedules.First().Departure, takeOff);
                Assert.AreEqual(newFlight.Schedules.First().Duration.TotalMinutes, 150);
            }
        }
예제 #3
0
        static public void Publish(FlightSchedule updatedSchedule)
        {
            var flightsRepository      = new FlightRepository();
            var reservationsRepository = new ReservationRepository();

            Flight updatedFlight = flightsRepository.GetFlight(updatedSchedule.Flight.FlightId);
            var    reservations  = reservationsRepository.FindBy(
                r => r.DepartureFlight.FlightScheduleID == updatedSchedule.FlightScheduleId);

            var travelers = from r in reservations
                            select r.TravelerId;

            var notification = new ToastNotificationTextAndImage
            {
                TargetClientDevices = travelers.ToList(),
                TextHeading         = string.Format("Flight {0} Was Rescheduled", updatedFlight.FlightNumber),
                TextBodyWrap        = string.Format("Flight {0} was rescheduled for {1}", updatedFlight.FlightNumber, updatedSchedule.ActualDeparture)
            };

            WNSManager.DispatchNotification(notification);
        }
예제 #4
0
 public async Task <Flight> GetFlight(long id)
 {
     return(await _repository.GetFlight(id));
 }