示例#1
0
        protected GetBusJourneysResponseModel Get_Bus_Journeys_Implementation(GetBusJourneysRequestModel request)
        {
            HttpPostAgent <GetBusJourneysRequestModel, GetBusJourneysResponseModel> agent = new HttpPostAgent <GetBusJourneysRequestModel, GetBusJourneysResponseModel>();

            agent.Url  = Config.Get_Bus_Journeys;
            agent.Body = request;

            return(agent.Send());
        }
示例#2
0
        public HttpResponseMessage Get_Bus_Journeys()
        {
            string body = Request.Content.ReadAsStringAsync().Result;

            GetBusJourneysRequestModel request = JsonConvert.DeserializeObject <GetBusJourneysRequestModel>(body);

            GetBusJourneysResponseModel response = Get_Bus_Journeys_Implementation(request);

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

            result.Content = new StringContent(response.ToString(), Encoding.UTF8, ContentTypes.Json);
            return(result);
        }
示例#3
0
        public HttpResponseMessage Journeys()
        {
            string body = Request.Content.ReadAsStringAsync().Result;

            JourneysRequestModel journeysRequestModel = JsonConvert.DeserializeObject <JourneysRequestModel>(body);

            GetBusJourneysRequestModel getBusJourneysRequestModel = new GetBusJourneysRequestModel();

            getBusJourneysRequestModel.Session           = new Model.obilet.Abstract.Json.JsonSession();
            getBusJourneysRequestModel.Session.DeviceID  = journeysRequestModel.Auth.DeviceKey;
            getBusJourneysRequestModel.Session.SessionID = journeysRequestModel.Auth.SessionKey;
            getBusJourneysRequestModel.Date               = DateTime.Now;
            getBusJourneysRequestModel.Language           = "tr-TR";
            getBusJourneysRequestModel.Data               = new GetBusJourneysRequestDataModel();
            getBusJourneysRequestModel.Data.OriginID      = journeysRequestModel.Data.OriginID;
            getBusJourneysRequestModel.Data.DestinationID = journeysRequestModel.Data.DestinationID;
            getBusJourneysRequestModel.Data.DepartureDate = journeysRequestModel.Data.Date;

            GetBusJourneysResponseModel getBusJourneysResponseModel = Get_Bus_Journeys_Implementation(getBusJourneysRequestModel);
            JourneysResponseModel       journeysResponseModel;

            if (getBusJourneysResponseModel.Status == ResponseStates.Success)
            {
                JourneysDataModel journeysDataModel = new JourneysDataModel();
                journeysDataModel.Journeys = new List <JsonJourney>();

                foreach (Model.obilet.Abstract.Json.JsonBusJourney busJourney in getBusJourneysResponseModel.Data)
                {
                    journeysDataModel.Journeys.Add(new JsonJourney()
                    {
                        DepartureTime = busJourney.Journey.Departure.ToString("HH:mm"),
                        ArrivalTime   = busJourney.Journey.Arrival.ToString("HH:mm"),
                        Origin        = new JsonLocation()
                        {
                            ID   = busJourney.OriginLocationID,
                            Name = busJourney.OriginLocation
                        },
                        Destination = new JsonLocation()
                        {
                            ID   = busJourney.DestinationLocationID,
                            Name = busJourney.DestinationLocation
                        },
                        Price = busJourney.Journey.InternetPrice + " " + busJourney.Journey.Currency
                    });
                }

                journeysResponseModel = new JourneysResponseModel()
                {
                    Meta = new JsonMeta()
                    {
                        Status  = "success",
                        Message = "Everything is fine"
                    },
                    Data = journeysDataModel
                };
            }
            else
            {
                journeysResponseModel = new JourneysResponseModel()
                {
                    Meta = new JsonMeta()
                    {
                        Status  = "fail",
                        Message = "Something went wrong"
                    },
                    Data = null
                };
            }

            string content = JsonConvert.SerializeObject(journeysResponseModel);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(content, Encoding.UTF8, ContentTypes.Json);
            return(response);
        }