public HttpResponseMessage GetSpecificSchedule(int id, int scheduleId)
        {
            FlightScheduleDTO   schedule = Flights.GetSchedule(scheduleId).ToFlightScheduleDTO();
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, schedule);

            return(response);
        }
Example #2
0
        public async Task <ActionResult <FlightScheduleDTO> > Add([FromBody] FlightScheduleDTO flightScheduleDto)
        {
            if (flightScheduleDto == null)
            {
                return(BadRequest());
            }

            await flightScheduleService.AddFlightScheduleAsync(flightScheduleDto);

            return(Ok(flightScheduleDto));
        }
Example #3
0
        public async Task <ActionResult <FlightScheduleDTO> > GetFlightScheduleAsync(int Id)
        {
            FlightScheduleDTO flightScheduleDto = await flightScheduleService.GetFlightScheduleAsync(Id);

            if (flightScheduleDto == null)
            {
                return(NotFound());
            }

            return(Ok(flightScheduleDto));
        }
Example #4
0
        public HttpResponseMessage Put(int id, int scheduleId, [FromBody] FlightScheduleDTO updatedScheduleDto)
        {
            FlightSchedule updatedSchedule = updatedScheduleDto.ToFlightSchedule();

            Flights.UpdateActualDeparture(updatedSchedule, updatedSchedule.ActualDeparture.Value);
            Flights.Save();

            // TODO: Lab07, Exercise 2, Task 1.6 : Send a flight update message to the queue
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Example #5
0
        public async Task <ActionResult <FlightScheduleDTO> > Delete(int Id)
        {
            FlightScheduleDTO flightScheduleDto = await flightScheduleService.GetFlightScheduleAsync(Id);

            if (flightScheduleDto == null)
            {
                return(NotFound());
            }

            await flightScheduleService.DeleteFlightScheduleAsync(flightScheduleDto);

            return(NoContent());
        }
Example #6
0
        public async Task <ActionResult <FlightScheduleDTO> > Update(int Id, [FromBody] FlightScheduleDTO flightScheduleDto)
        {
            if (flightScheduleDto == null)
            {
                return(NotFound());
            }

            flightScheduleDto.Id = Id;

            await flightScheduleService.UpdateFlightScheduleAsync(flightScheduleDto);

            return(Ok(flightScheduleDto));
        }
        public async Task DeleteFlightScheduleAsync(FlightScheduleDTO flightScheduleDTO)
        {
            var flightSchedule = await unitOfWork.FlightScheduleRepository.Get(flightScheduleDTO.Id);

            if (flightSchedule == null)
            {
                throw new Exception("Not found");
            }



            await unitOfWork.FlightScheduleRepository.Delete(flightSchedule);
        }
        public HttpResponseMessage Put(int id, int scheduleId, [FromBody] FlightScheduleDTO updatedScheduleDto)
        {
            FlightSchedule updatedSchedule = updatedScheduleDto.ToFlightSchedule();

            Flights.UpdateActualDeparture(updatedSchedule, updatedSchedule.ActualDeparture.Value);
            Flights.Save();

            // TODO: Lab07, Exercise 2, Task 1.6 : Send a flight update message to the queue
            updatedSchedule.FlightScheduleId = id;
            BrokeredMessage message = new BrokeredMessage(updatedScheduleDto);

            message.ContentType = "UpdatedSchedule";
            queueClient.Send(message);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
        public static FlightSchedule ToFlightSchedule(this FlightScheduleDTO dto)
        {
            FlightSchedule flightSchedule = new FlightSchedule
            {
                Departure       = dto.Departure,
                Duration        = dto.Duration,
                ActualDeparture = dto.ActualDeparture,
                Flight          = new Flight
                {
                    Source             = dto.Flight.Source.ToLocation(),
                    Destination        = dto.Flight.Destination.ToLocation(),
                    FlightNumber       = dto.Flight.FlightNumber,
                    FrequentFlyerMiles = dto.Flight.FrequentFlyerMiles,
                    FlightId           = dto.Flight.FlightId
                },
                FlightScheduleId = dto.FlightScheduleId
            };

            return(flightSchedule);
        }
        public static FlightScheduleDTO ToFlightScheduleDTO(this FlightSchedule flightSchedule)
        {
            FlightScheduleDTO dto = new FlightScheduleDTO
            {
                Departure       = flightSchedule.Departure,
                Duration        = flightSchedule.Duration,
                ActualDeparture = flightSchedule.ActualDeparture,
                Flight          = new FlightDTO
                {
                    Source             = flightSchedule.Flight.Source.ToLocationDTO(),
                    Destination        = flightSchedule.Flight.Destination.ToLocationDTO(),
                    FlightNumber       = flightSchedule.Flight.FlightNumber,
                    FrequentFlyerMiles = flightSchedule.Flight.FrequentFlyerMiles,
                    FlightId           = flightSchedule.Flight.FlightId
                },
                FlightScheduleId = flightSchedule.FlightScheduleId,
            };

            return(dto);
        }
        public ActionResult UpdateActualDeparture(int id, int scheduleId, string date, string time)
        {
            DateTime newDeparture = DateTime.Parse(date + " " + time);

            using (var proxy = new HttpClient()
            {
                BaseAddress = new Uri(_companionService)
            })
            {
                FlightScheduleDTO schedule = proxy.GetAsync(
                    string.Format("Flights/{0}?scheduleId={1}", id, scheduleId)).
                                             Result.Content.ReadAsAsync <FlightScheduleDTO>().Result;

                schedule.ActualDeparture = newDeparture;

                proxy.PutAsJsonAsync(
                    string.Format("Flights/{0}?scheduleId={1}", id, scheduleId),
                    schedule).Wait();
            }
            return(Content("updated"));
        }
Example #12
0
        public ActionResult UpdateActualDeparture(int id, int scheduleId, string date, string time)
        {
            using (var proxy = new HttpClient()
            {
                BaseAddress = new Uri(_companionService)
            })
            {
                FlightScheduleDTO schedule = proxy.GetAsync(
                    string.Format("Flights/{0}?scheduleId={1}", id, scheduleId)).
                                             Result.Content.ReadAsAsync <FlightScheduleDTO>().Result;

                var      datePart     = string.IsNullOrEmpty(date) ? schedule.Departure.Date : DateTime.Parse(date);
                var      timePart     = string.IsNullOrEmpty(time) ? schedule.Departure : DateTime.Parse(time);
                DateTime newDeparture = datePart.Add(timePart.TimeOfDay);
                schedule.Departure = newDeparture;

                proxy.PutAsJsonAsync(
                    string.Format("Flights/{0}?scheduleId={1}", id, scheduleId),
                    schedule).Wait();
            }
            return(Content("updated"));
        }
 public static void Run([ServiceBusTrigger("FlightUpdatesQueue", AccessRights.Manage, Connection = "ServiceBusConnectionString")] FlightScheduleDTO updatedScheduleDto, TraceWriter log)
 {
     MessageHandler.Publish(updatedScheduleDto.ToFlightSchedule());
 }
        public async Task UpdateFlightScheduleAsync(FlightScheduleDTO flightScheduleDTO)
        {
            var flightSchedule = mapper.Map <FlightSchedule>(flightScheduleDTO);

            await unitOfWork.FlightScheduleRepository.Update(flightSchedule);
        }
Example #15
0
 private static void HandleMessageContent(FlightScheduleDTO updatedScheduleDto)
 {
     MessageHandler.Publish(updatedScheduleDto.ToFlightSchedule());
 }