public XDocument getservice(GetAvailableServicesRequest _objGetAvailableServicesRequest)
 {
     XDocument doc = null;
     XElement root = null;
     string servicename = "GetAvailableServices";
     XmlDocument servicesNames = new XmlDocument();
     try
     {
         XNamespace fc = AppStatic.BusIndiaWebService;
         XNamespace soapenv = AppStatic.XmlSoapSchema;
         doc = new XDocument(new XDeclaration("1.0", "utf-16", "yes"),
         root = new XElement(soapenv + "Envelope",
             new XAttribute(XNamespace.Xmlns + "com", fc.NamespaceName),
             new XAttribute(XNamespace.Xmlns + "soapenv", soapenv.NamespaceName),
             new XElement(soapenv + "Header"),
             new XElement(soapenv + "Body",
             new XElement(fc + servicename,
             new XElement("arg0",
                 new XElement("biFromPlace",
                     new XElement("placeCode", _objGetAvailableServicesRequest.placeCodeFrom),
                     new XElement("placeID", _objGetAvailableServicesRequest.placeIDFrom),
                     new XElement("placeName", _objGetAvailableServicesRequest.placeNameFrom)
                     ),
                 new XElement("biToPlace",
                     new XElement("placeCode", _objGetAvailableServicesRequest.placeCodeTo),
                     new XElement("placeID", _objGetAvailableServicesRequest.placeIDto),
                     new XElement("placeName", _objGetAvailableServicesRequest.placeNameTo)
                     ),
                 new XElement("journeyDate", _objGetAvailableServicesRequest.journeyDate),
                 new XElement("wsUser",
                     new XElement("franchUserID", _objGetAvailableServicesRequest.franchUserID),
                     new XElement("password", _objGetAvailableServicesRequest.password),
                     new XElement("userID", _objGetAvailableServicesRequest.userID),
                     new XElement("userKey", _objGetAvailableServicesRequest.userKey),
                     new XElement("userName", _objGetAvailableServicesRequest.userName),
                     new XElement("userRole", _objGetAvailableServicesRequest.userRole),
                     new XElement("userStatus", _objGetAvailableServicesRequest.userStatus),
                     new XElement("userType", _objGetAvailableServicesRequest.userType)
                 )
             )
             )
             )
             )
         );
     }
     catch (Exception ex)
     {
     }
     return doc;
 }
        public  void postXMLData1()
        {
            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {
            try
            {
            
                string uri = AppStatic.WebServiceBaseURL;  // some xml string
                Uri _url = new Uri(uri, UriKind.RelativeOrAbsolute);
                GetAvailableServicesRequest _objAGR = new GetAvailableServicesRequest();
                _objAGR.franchUserID = AppStatic.franchUserID;
                _objAGR.password = AppStatic.password;
                _objAGR.userID = AppStatic.userID;
                _objAGR.userKey = AppStatic.userKey;
                _objAGR.userName = AppStatic.userName;
                _objAGR.userRole = AppStatic.userRole;
                _objAGR.userStatus = AppStatic.userStatus;
                _objAGR.userType = AppStatic.userType;
                _objAGR.placeNameFrom = txtBFromLocationT.Text;
                _objAGR.placeNameTo = txtBToLocationT.Text;
                _objAGR.placeIDFrom = txtBFromID.Text;
                _objAGR.placeIDto = txtBToID.Text;
                _objAGR.placeCodeFrom = txtBFromCode.Text;
                _objAGR.placeCodeTo = txtBToCode.Text;
                string d = txtBDateTab.Text;
                System.DateTime dt = System.DateTime.ParseExact(d, "dd MMM yyyy", CultureInfo.InvariantCulture);
                string Date = dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
                _objAGR.journeyDate = Date;

                xmlUtility listings = new xmlUtility();
                XDocument element = listings.getservice(_objAGR);
                string stringXml = element.ToString();
                var httpClient = new Windows.Web.Http.HttpClient();
                var info = AppStatic.WebServiceAuthentication;
                var token = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(info));
                httpClient.DefaultRequestHeaders.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("Basic", token);
                httpClient.DefaultRequestHeaders.Add("SOAPAction", "");
                Windows.Web.Http.HttpRequestMessage httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, _url);
                httpRequestMessage.Headers.UserAgent.TryParseAdd("Mozilla/4.0");
                IHttpContent content = new HttpStringContent(stringXml, Windows.Storage.Streams.UnicodeEncoding.Utf8);
                httpRequestMessage.Content = content;
                Windows.Web.Http.HttpResponseMessage httpResponseMessage = await httpClient.SendRequestAsync(httpRequestMessage);
                string strXmlReturned = await httpResponseMessage.Content.ReadAsStringAsync();
                XmlDocument xDoc = new XmlDocument();
                XDocument loadedData = XDocument.Parse(strXmlReturned);
                XDocument element1 = listings.getAvailableServicelayout(_objAGR);
                string stringXml1 = element1.ToString();

                byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(stringXml1.ToString());
                StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("HistoryTest1.xml", CreationCollisionOption.OpenIfExists);
                String historyTestContent = await FileIO.ReadTextAsync(file);
                using (var stream = await file.OpenStreamForWriteAsync())
                {
                    stream.Seek(0, SeekOrigin.End);
                    stream.Write(fileBytes, 0, fileBytes.Length);
                }

                List<XElement> _list = (from t1 in loadedData.Descendants("wsResponse") select t1).ToList();
                List<PlaceList> seatsList = new List<PlaceList>();
                string _msg = "";
                if (_list != null)
                {
                    foreach (XElement _elemet in _list)
                    {
                        PlaceList _obj = new PlaceList();
                        _obj.message = _elemet.Element("message").Value.ToString();
                        seatsList.Add(_obj);
                    }
                    _msg = seatsList.FirstOrDefault().message.ToString();
                }                
                if (_msg != "FAILURE")
                {
                    var sdata = loadedData.Descendants("service").
                    Select(x => new GetAvailableService
                    {
                        arrivalDate = x.Element("arrivalDate").Value,
                        arrivalTime = x.Element("arrivalTime").Value,
                        classID = x.Element("classID").Value,
                        classLayoutID = x.Element("classLayoutID").Value,
                        className = x.Element("className").Value,
                        corpCode = x.Element("corpCode").Value,
                        departureTime = x.Element("departureTime").Value,
                        destination = x.Element("destination").Value,
                        fare = x.Element("fare").Value,
                        journeyDate = x.Element("journeyDate").Value,
                        journeyHours = x.Element("journeyHours").Value,
                        maxSeatsAllowed = x.Element("maxSeatsAllowed").Value,
                        origin = x.Element("origin").Value,
                        placeIDFrom = x.Element("biFromPlace").Element("placeID").Value,
                        placeIDto = x.Element("biToPlace").Element("placeID").Value,
                        refundStatus = x.Element("refundStatus").Value,
                        routeNo = x.Element("routeNo").Value,
                        seatsAvailable = x.Element("seatsAvailable").Value,
                        seatStatus = x.Element("seatStatus").Value,
                        serviceID = x.Element("serviceID").Value,
                        startPoint = x.Element("startPoint").Value,
                        studID = x.Element("stuID").Value,
                        tripCode = x.Element("tripCode").Value,
                        viaPlaces = x.Element("viaPlaces").Value
                    });
                    foreach (var item in sdata)
                    {
                        GetAvailableService gas = new GetAvailableService();
                        gas.arrivalDate = item.arrivalDate;
                        gas.arrivalTime = item.arrivalTime;
                        gas.classID = item.classID;
                        gas.classLayoutID = item.classLayoutID;
                        gas.className = item.className;
                        gas.corpCode = item.corpCode;
                        gas.departureTime = item.departureTime;
                        gas.destination = item.destination;
                        gas.fare = item.fare;
                        gas.journeyDate = item.journeyDate;
                        gas.journeyHours = item.journeyHours;
                        gas.maxSeatsAllowed = item.maxSeatsAllowed;
                        gas.origin = item.origin;
                        gas.placeIDFrom = item.placeIDFrom;
                        gas.placeIDto = item.placeIDto;
                        gas.refundStatus = item.refundStatus;
                        gas.routeNo = item.routeNo;
                        gas.seatsAvailable = item.seatsAvailable;
                        gas.seatStatus = item.seatStatus;
                        gas.serviceID = item.serviceID;
                        gas.startPoint = item.startPoint;
                        gas.studID = item.studID;
                        gas.tripCode = item.tripCode;
                        gas.viaPlaces = item.viaPlaces;
                        availableservice.Add(gas);
                    }
                    ListMenuItems.ItemsSource = sdata;

                    string MaxPriceresult = sdata.OrderByDescending(x => x.fare).Select(x => x.fare).FirstOrDefault().ToString();
                    if (MaxPriceresult != null)
                    {
                        txtBMaxPriceCurrent.Text = MaxPriceresult;
                        txtBMaxPrice.Text = MaxPriceresult;
                        maxPrice = Convert.ToInt32(MaxPriceresult);
                        MaxPrice = Convert.ToInt32(MaxPriceresult);
                        Thumb2PositionPrice = Convert.ToInt32(MaxPriceresult);
                    }

                    string MinPriceresult = sdata.OrderBy(x => x.fare).Select(x => x.fare).FirstOrDefault().ToString();
                    if (MinPriceresult != null)
                    {
                        txtBMinPrice.Text = MinPriceresult;
                        txtBMinPriceCurrent.Text = MinPriceresult;
                        minPrice = Convert.ToInt32(MinPriceresult);
                        MinPrice = Convert.ToInt32(MinPriceresult);
                        Thumb1PositionPrice = Convert.ToInt32(MinPriceresult);
                    }
                    ListMenuItemsFilterCorp.ItemsSource = sdata.Select(x => x.corpCode).Distinct().ToList();
                    ListMenuItemsFilterBusType.ItemsSource = sdata.Select(x => x.className).Distinct().ToList();

                    FilterFunVisible();
                }
                else
                {
                    FilterFunCollapsed();

                }
             
            }
            catch (Exception ex)
            {
                LoaderPop.Visibility = Visibility.Collapsed;
                ErrorpopUp.Visibility = Visibility.Visible;               
                ExceptionLog obj = new ExceptionLog();
                Error objError = new Error();
                objError.ErrorEx = ex.Message;
                obj.CreateLogFile(objError);
            }
            }).AsTask();
        }
        public XDocument getAvailableServicelayout(GetAvailableServicesRequest _objGetSeatlayoutRequest)
        {
            XDocument doc = null;
            XmlDocument servicesNames = new XmlDocument();
            try
            {

                doc = new XDocument(
                    new XElement("arg0",
                        new XElement("biFromPlace",
                            new XElement("placeCode", _objGetSeatlayoutRequest.placeCodeFrom),
                            new XElement("placeID", _objGetSeatlayoutRequest.placeIDFrom),
                            new XElement("placeName", _objGetSeatlayoutRequest.placeNameFrom)
                            ),
                        new XElement("biToPlace",
                            new XElement("placeCode", _objGetSeatlayoutRequest.placeCodeTo),
                            new XElement("placeID", _objGetSeatlayoutRequest.placeIDto),
                            new XElement("placeName", _objGetSeatlayoutRequest.placeNameTo)
                            ),

                         new XElement("journeyDate", _objGetSeatlayoutRequest.journeyDate),

                        new XElement("wsUser",
                            new XElement("franchUserID", _objGetSeatlayoutRequest.franchUserID),
                            new XElement("password", _objGetSeatlayoutRequest.password),
                            new XElement("userID", _objGetSeatlayoutRequest.userID),
                            new XElement("userKey", _objGetSeatlayoutRequest.userKey),
                            new XElement("userName", _objGetSeatlayoutRequest.userName),
                            new XElement("userRole", _objGetSeatlayoutRequest.userRole),
                            new XElement("userStatus", _objGetSeatlayoutRequest.userStatus),
                            new XElement("userType", _objGetSeatlayoutRequest.userType)
                        )
                    )

                );
            }
            catch (Exception ex)
            {
            }
            return doc;
        }
        public async void postXMLData1()
        {
            try
            {
                //var sampleFile1 = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("HistoryTest1.xml");
                //await sampleFile1.DeleteAsync(StorageDeleteOption.PermanentDelete);     

                StorageFile sampleFile = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("HistoryTest1.xml");
                String timestamp = await FileIO.ReadTextAsync(sampleFile);
                String HistorySearch = "<arg>" + timestamp + "</arg>";
                XDocument loadedDatas = XDocument.Parse(HistorySearch);
                var sdata = loadedDatas.Descendants("arg0").
                       Select(x => new GetAvailableServicesRequest
                       {
                           placeCodeFrom = x.Element("biFromPlace").Element("placeCode").Value,
                           placeCodeTo = x.Element("biToPlace").Element("placeCode").Value,
                           placeIDFrom = x.Element("biFromPlace").Element("placeID").Value,
                           placeIDto = x.Element("biToPlace").Element("placeID").Value,
                           placeNameFrom = x.Element("biFromPlace").Element("placeName").Value,
                           placeNameTo = x.Element("biToPlace").Element("placeName").Value,
                           journeyDate = x.Element("journeyDate").Value

                       });
                ListMenuItems.ItemsSource = sdata;

                List<XElement> _srow = (from t1 in loadedDatas.Descendants("biFromPlace") select t1).ToList();
                List<GetAvailableServicesRequest> srow = new List<GetAvailableServicesRequest>();
                foreach (XElement _elemetsr in _srow)
                {
                    GetAvailableServicesRequest _objsr = new GetAvailableServicesRequest();
                    _objsr.placeCodeFrom = _elemetsr.Element("placeCode").Value.ToString();                   
                    _objsr.placeIDFrom = _elemetsr.Element("placeID").Value.ToString();                  
                    _objsr.placeNameFrom = _elemetsr.Element("placeName").Value.ToString();                 
                    srow.Add(_objsr);
                }
            }
            catch(Exception ex)
            {
                btnClearAll.Visibility = Visibility.Collapsed;
                PopupError.Visibility = Visibility.Visible;
                ExceptionLog obj= new ExceptionLog();
                Error objError = new Error();
                objError.ErrorEx = ex.Message;
                obj.CreateLogFile(objError);
            }

        }