Beispiel #1
0
        /// <summary>
        /// Insert flight into a temporal list for then save the flight information in the database of fights and itineraries.
        /// </summary>
        /// <param name="model"></param>
        public void InsertFlightIntoList(BasicItineraryModel model)
        {
            var airlineInfo = _airlinesRepository.GetAirlinebyName(model.AirlineName);

            _airportsRepository  = new AirportsRepository();
            _passengerRepository = new PassengerRepository();

            if (airlineInfo == null)
            {
                return;
            }

            var airlineId    = airlineInfo.AirlineID;
            var airportInfo1 = _airportsRepository.GetAirportbyName(model.DepartureName);
            var airportInfo2 = _airportsRepository.GetAirportbyName(model.ArrivalName);

            if ((airportInfo1 == null) || (airportInfo2 == null))
            {
                return;
            }

            var departureLocation = airportInfo1.AirportID;
            var arrivalLocation   = airportInfo2.AirportID;

            var flight = new Flights
            {
                AirlineID         = airlineId,
                DepartureLocation = departureLocation,
                FlightNumber      = model.FlightNumber,
                ArrivalLocation   = arrivalLocation,
                DepartureDateTime = (DateTime)model.DepartureTime,
                ArrivalDateTime   = (DateTime)model.ArrivalTime,
            };

            _listF.Add(flight);
            _listIti.Add(model);


            var passenger = _passengerRepository.Get(model.PassengerEmail);

            if (passenger == null)
            {
                passenger = new Passengers
                {
                    PassengerEmail    = model.PassengerEmail,
                    PassengerLastName = model.PassengerLastName,
                    PassengerName     = model.PassengerName,
                    TokenId           = "TokenID"
                };

                _passengerRepository.Add(passenger);
            }
        }
        public IHttpActionResult Get(int id)
        {
            Passenger passenger = passengerRepository.Get(id);

            if (passenger == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(Ok(passenger));
            }
        }
Beispiel #3
0
        public ActionResult InsertBasic(string Stops, string TripTypeName, string PassengerName, string PassengerLastName, string PassengerEmail)
        {
            _airlinesRepository         = new AirlinesRepository();
            _airportsRepository         = new AirportsRepository();
            _tagsRepository             = new TagsRepository();
            _passengerRepository        = new PassengerRepository();
            _itineraryPingersRepository = new ItineraryPingersRepository();
            new UserTagsRepository();
            _usersRepository            = new UsersRepository();
            _monitoredFlightsRepository = new MonitoredFlightsRepository();
            _itinerarysRepository       = new ItinerarysRepository();
            _flightsRepository          = new FlightsRepository();
            new GatewayAirlineRepository();

            #region Create Itinerary

            var model = new BasicItineraryModel
            {
                //ConnxysTagId = ConnxysTagId,
                DepartureTime      = _listF.First().DepartureDateTime,
                ArrivalTime        = _listF.Last().ArrivalDateTime,
                DepartureName      = _airportsRepository.Get(_listF.First().DepartureLocation).AirportDesignationLetters,
                ArrivalName        = _airportsRepository.Get(_listF.Last().ArrivalLocation).AirportDesignationLetters,
                Stops              = Convert.ToInt32(Stops),
                TripTypeName       = TripTypeName,
                DepartDateTimeUTC  = _listIti.First().DepartDateTimeUTC,
                ArrivalDateTimeUTC = _listIti.Last().ArrivalDateTimeUTC
            };

            object jsonData;
            //Get Passenger Information
            var passenger = _passengerRepository.Get(PassengerEmail);
            passenger.PassengerName     = PassengerName;
            passenger.PassengerLastName = PassengerLastName;
            _passengerRepository.Update(passenger);

            var itinerary = new Itinerary
            {
                //UserID = userInfo.userID,
                UserID               = 0,
                Stops                = model.Stops,
                DepartDateTime       = model.DepartureTime,
                ArrivalDateTime      = model.ArrivalTime,
                AirlineReservationID = model.AirlineReservationId,
                RetStops             = model.RetStops,
                TripType             = (short?)int.Parse(model.TripTypeName),
                From               = model.DepartureName,
                To                 = model.ArrivalName,
                CreationDate       = DateTime.UtcNow,
                Type               = "Real Flight",
                PassengerID        = passenger != null ? passenger.PassengerID : 0,
                DepartDateTimeUTC  = model.DepartDateTimeUTC,
                ArrivalDateTimeUTC = model.ArrivalDateTimeUTC
            };

            try
            {
                //insert the new itinerary
                _itinerarysRepository.Add(itinerary);
                var itineraryId = itinerary.ItineraryID;

                if (itineraryId > 0)
                {
                    var connxysWcfRestService = new ConnxysWCFRestService();
                    var flightsList           = new StringBuilder();
                    var currentFlight         = 0L;
                    var flightInd             = 0;

                    //insert all the flights
                    foreach (var flightItem in _listF)
                    {
                        flightItem.ItineraryID = itineraryId;
                        _flightsRepository.Add(flightItem);

                        if (flightInd == (_listF.Count - 1))
                        {
                            flightsList.Append(flightItem.FlightID);
                        }
                        else
                        {
                            flightsList.Append(flightItem.FlightID).Append("-");
                        }

                        if (flightInd == 0)
                        {
                            currentFlight = flightItem.FlightID;
                        }


                        var monitoredFlights = new MonitoredFlights();
                        {
                            monitoredFlights.FlightId          = flightItem.FlightID;
                            monitoredFlights.FlightNumber      = flightItem.FlightNumber;
                            monitoredFlights.StartDate         = Convert.ToDateTime(flightItem.DepartureDateTime);
                            monitoredFlights.EndDate           = Convert.ToDateTime(flightItem.ArrivalDateTime);
                            monitoredFlights.DepartureLocation = flightItem.DepartureLocation;
                            monitoredFlights.ArrivalLocation   = flightItem.ArrivalLocation;
                            monitoredFlights.Status            = 0;

                            var airline = _airlinesRepository.Get(flightItem.AirlineID);
                            monitoredFlights.AirlineDesignator = airline.AirlineDesignator;
                            monitoredFlights.AirlineName       = airline.AirlineName;
                        }

                        //Insert monitoredflight in the database
                        _monitoredFlightsRepository.Add(monitoredFlights);

                        // Increase Flight index
                        flightInd++;
                    }

                    //insert all the bags
                    foreach (var bagItem in _listB)
                    {
                        var baggageInfo = new BaggageInfo {
                            BagIATANumber     = bagItem.BagIATANumber,
                            ItineraryId       = itineraryId,
                            PingerId          = bagItem.ConnxysTagID,
                            PassengerEmail    = passenger.PassengerEmail,
                            PassengerLastName = passenger.PassengerLastName,
                            PassengerName     = passenger.PassengerName
                        };

                        connxysWcfRestService.UpdateBaggageInfo(baggageInfo);

                        var itineraryPinger = new ItineraryPingers {
                            ItineraryID  = itinerary.ItineraryID,
                            ConnxysTagID = bagItem.ConnxysTagID
                        };

                        _itineraryPingersRepository.Add(itineraryPinger);
                    }
                    _listB = new List <BagTagDesignation>();

                    var creationDate = DateTime.Now.ToUniversalTime();
                    _storeProcedureRepository = new StoreProcedureRepository();
                    _storeProcedureRepository.CreateOutgoingMessage(itinerary.ItineraryID, null, null, null, null, Convert.ToInt64(model.TagId), "Manually", creationDate, false);

                    //Create notification message to sent a message to the passenger abput the itinerary creation
                    var notification = new NotificationMessage
                    {
                        Title   = "Itinerary Information",
                        Message = string.Format
                                      ("Hello {0}!  We’re excited to have you fly with us on flight #: {1} to {2}.  We’ll notify you when your bag is checked in, when it’s been loaded aboard your flight, and where you can reclaim it in {3}.  Enjoy your flight with us!", passenger.PassengerName, _listF[0].FlightNumber.ToString(), model.ArrivalName, model.ArrivalName),
                        TokenId = passenger.TokenId
                    };

                    foreach (var fl in _listF)
                    {
                        var airlineDesignator = _airlinesRepository.Get(fl.AirlineID);

                        var callUpdateFlight = new ConnxysWCFRestService();
                        if (fl.DepartureDateTime == null)
                        {
                            continue;
                        }
                        if (fl.ArrivalDateTime != null)
                        {
                            callUpdateFlight.UpdateSimpleFlight(
                                fl.FlightID.ToString(CultureInfo.InvariantCulture),
                                airlineDesignator.AirlineDesignator,
                                fl.FlightNumber.ToString(CultureInfo.InvariantCulture),
                                fl.DepartureDateTime.Value.ToString(CultureInfo.InvariantCulture),
                                fl.ArrivalDateTime.Value.ToString(CultureInfo.InvariantCulture));
                        }
                    }

                    _listF = new List <Flights>();

                    jsonData = new {
                        status      = "Ok",
                        itineraryId = itinerary.ItineraryID
                    };

                    //Send push notification about itinerary creation to the passenger
                    connxysWcfRestService.SendPushNotification(notification);
                }
                else
                {
                    //throw error the itinerary can not be created
                    _listF = new List <Flights>();
                    PopulateList();
                    jsonData = new
                    {
                        status  = "Failed",
                        message = "Error: The itinerary was not added."
                    };
                    return(Json(jsonData, JsonRequestBehavior.AllowGet));
                }

                return(Json(jsonData, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                //throw error the itinerary can not be created
                _listF   = new List <Flights>();
                jsonData = new
                {
                    status  = "Failed",
                    message = "Error: The itinerary was not added."
                };
                return(Json(jsonData, JsonRequestBehavior.AllowGet));
            }

            #endregion
        }