Exemplo n.º 1
0
        public List<PropertyModel> GetProperty()
        {
            List<PropertyModel> model = new List<PropertyModel>();
            PaginationModel paging = new PaginationModel();
            XmlDocument doc = new XmlDocument();
            doc.Load(HttpContext.Current.Server.MapPath("propertyList.xml"));
            XmlNode RETSRes = doc.SelectSingleNode("/RETS");
            XmlNode RETSRes2 = doc.DocumentElement.SelectSingleNode("/RETS-RESPONSE");
            XmlNode RETSRes4 = doc.DocumentElement.SelectSingleNode("RETS-RESPONSE");
            XmlNode RETSRes5 = doc.DocumentElement.SelectSingleNode("RETS-RESPONSE/Pagination");
            XmlNode RETSRes6 = RETSRes.SelectSingleNode("RETS-RESPONSE/Pagination");
            XmlNode RETSRes3 = RETSRes.SelectSingleNode("/RETS-RESPONSE");

            paging.TotalRecores = Convert.ToInt32(RETSRes.SelectSingleNode("RETS-RESPONSE/Pagination/TotalRecords").InnerText);
            paging.Limit = Convert.ToInt32(RETSRes.SelectSingleNode("RETS-RESPONSE/Pagination/Limit").InnerText);
            paging.Offset = Convert.ToInt32(RETSRes.SelectSingleNode("RETS-RESPONSE/Pagination/Offset").InnerText);
            paging.TotalPages = Convert.ToInt32(RETSRes.SelectSingleNode("RETS-RESPONSE/Pagination/TotalPages").InnerText);
            paging.RecordsReturned = Convert.ToInt32(RETSRes.SelectSingleNode("RETS-RESPONSE/Pagination/RecordsReturned").InnerText);

            XmlNodeList proDetails = RETSRes.SelectNodes("RETS-RESPONSE/PropertyDetails");
            foreach (XmlNode pro in proDetails)
            {
                PropertyModel promodel = new PropertyModel();
                List<AgentModel> agentList = new List<AgentModel>();
                LandModel land = new LandModel();
                BuildingModel building = new BuildingModel();

                XmlAttributeCollection proatt = pro.Attributes;
                promodel.PropertyDetailsID = Convert.ToInt32(proatt["ID"].Value);
                promodel.LastUpdated = Convert.ToDateTime(proatt["LastUpdated"].Value);

                promodel.ListingID = pro.SelectSingleNode("ListingID").InnerText;
                XmlNodeList agentsxml = pro.SelectNodes("AgentDetails");
                foreach (XmlNode agentxml in agentsxml)
                {
                    AgentModel Agmodel = new AgentModel();
                    OfficeModel offiModel = new OfficeModel();
                    Agmodel.AgentDetailsID = Convert.ToInt32(agentxml.Attributes["ID"].Value);
                    Agmodel.Name = agentxml.SelectSingleNode("Name").InnerText;
                    Agmodel.OfficeID = Convert.ToInt32(agentxml.SelectSingleNode("Office/@ID").Value);
                    offiModel.OfficeID = Convert.ToInt32(agentxml.SelectSingleNode("Office/@ID").Value);
                    offiModel.Name = agentxml.SelectSingleNode("Office/Name").InnerText;
                    offiModel.City = agentxml.SelectSingleNode("Office/Address/City").InnerText;
                    Agmodel.Position = agentxml.SelectSingleNode("Position").InnerText;

                    Agmodel.Office = offiModel;
                    agentList.Add(Agmodel);
                }
                promodel.Board = pro.SelectSingleNode("Board").InnerText;
                promodel.Business = pro.SelectSingleNode("Business").InnerText;
                building.BathroomTotal =Convert.ToInt32(pro.SelectSingleNode("Building/BathroomTotal").InnerText);
                building.BedroomsTotal =Convert.ToInt32(pro.SelectSingleNode("Building/BedroomsTotal").InnerText);
                building.CoolingType= pro.SelectSingleNode("Building/CoolingType").InnerText;
                building.FireplacePresent=Convert.ToBoolean(pro.SelectSingleNode("Building/FireplacePresent").InnerText.ToLower());
                building.HeatingFuel= pro.SelectSingleNode("Building/HeatingFuel").InnerText;
                building.HeatingType = pro.SelectSingleNode("Building/HeatingType").InnerText;
                building.SizeInterior = pro.SelectSingleNode("Building/SizeInterior").InnerText;
                building.Type = pro.SelectSingleNode("Building/Type").InnerText;

               land.Acreage=Convert.ToBoolean(pro.SelectSingleNode("Land/Acreage").InnerText);
               land.SizeTotal= Convert.ToInt32(pro.SelectSingleNode("Land/SizeTotal").InnerText.Replace("sqft","").Trim());
               land.SizeTotalText = pro.SelectSingleNode("Land/SizeTotalText").InnerText;
               promodel.AddressLine1= pro.SelectSingleNode("Address/AddressLine1").InnerText;
               promodel.StreatAddress = pro.SelectSingleNode("Address/StreetAddress").InnerText;
               promodel.City= pro.SelectSingleNode("Address/City").InnerText;
               promodel.PostalCode= pro.SelectSingleNode("Address/PostalCode").InnerText;
               promodel.Country= pro.SelectSingleNode("Address/Country").InnerText;
               promodel.Province= pro.SelectSingleNode("Address/Province").InnerText;

                promodel.Features= pro.SelectSingleNode("Features").InnerText;
                promodel.FarmType= pro.SelectSingleNode("FarmType").InnerText;
                if(pro.SelectSingleNode("Lease")!=null)
                promodel.Lease= pro.SelectSingleNode("Lease").InnerText;
                if (pro.SelectSingleNode("LeasePerTime") != null)
                promodel.LeasePerTime= pro.SelectSingleNode("LeasePerTime").InnerText;
                promodel.OwnershipType= pro.SelectSingleNode("OwnershipType").InnerText;
                promodel.Price=Convert.ToDecimal(pro.SelectSingleNode("Price").InnerText);
                promodel.PropertyType= pro.SelectSingleNode("PropertyType").InnerText;
                promodel.PublicRemarks= pro.SelectSingleNode("PublicRemarks").InnerText;
                promodel.TransactionType= pro.SelectSingleNode("TransactionType").InnerText;
                promodel.UtilitiesAvailable = pro.SelectSingleNode("UtilitiesAvailable").InnerText;
                promodel.ViewType= pro.SelectSingleNode("ViewType").InnerText;
                promodel.WaterFrontType = pro.SelectSingleNode("WaterFrontType").InnerText;
                promodel.AnalyticsClick = pro.SelectSingleNode("AnalyticsClick").InnerText;
                promodel.AnalyticsView = pro.SelectSingleNode("AnalyticsView").InnerText;
                promodel.MoreInformationLink = pro.SelectSingleNode("MoreInformationLink").InnerText;

                XmlNodeList photoes = pro.SelectNodes("Photo/PropertyPhoto");
                List<PhotoModel> picsModel = new List<PhotoModel>();
                foreach(XmlNode photo in photoes)
                {
                    PhotoModel phomodel = new PhotoModel();
                    phomodel.SequenceID =Convert.ToInt32(photo.SelectSingleNode("SequenceId").InnerText);
                    phomodel.LastUpdated = Convert.ToDateTime(photo.SelectSingleNode("LastUpdated").InnerText);
                    picsModel.Add(phomodel);
                }
                promodel.Photos = picsModel;
                promodel.Agents = agentList;
                promodel.Building = building;
                promodel.Land = land;
                model.Add(promodel);
            }
            return model;
        }
Exemplo n.º 2
0
        public List<PropertyModel> SearchPropertyXml2(string SearchType, string Class, string QueryType, string Query, int Count = 1, string Limit = "None", int Offset = 1, string Culture = "en-CA", string Format = "STANDARD-XML")
        {
            string requestArguments = "?Format=" + Format + "&SearchType=" + SearchType + "&Class=" + Class + "&QueryType=" + QueryType + "&Query=" + Query + "&Count=" + Count + "&Limit=" + Limit + "&Offset=" + Offset + "&Culture=" + Culture;
            string searchService = RetsUrl + "/Search.svc/Search" + requestArguments;

            httpWebRequest = (HttpWebRequest)WebRequest.Create(searchService);
            httpWebRequest.CookieContainer = cookieJar; //GRAB THE COOKIE
            httpWebRequest.Credentials = requestCredentials; //PASS CREDENTIALS
            Dictionary<string, string> dic = new Dictionary<string, string>();
            try
            {
                List<PropertyModel> model = new List<PropertyModel>();
                XmlTextReader reader = new XmlTextReader(HttpContext.Current.Server.MapPath("propertyList.xml"));
                PropertyModel property = new PropertyModel();
                while (reader.Read())
                {
                    Console.WriteLine(reader.Name + " Value" + reader.Value);
                    switch (reader.Name)
                    {
                        case "RETS":
                            if (reader.HasAttributes)
                            {
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.Name == "ReplyCode" & reader.Value == "0")
                                    {
                                        dic.Add(reader.Name, reader.Value);
                                    }
                                    else
                                    {
                                        dic.Add(reader.Name, reader.Value);
                                    }
                                }
                            }
                            break;
                        case "TotalRecords":
                            dic = ReadXMLElement(reader);
                            break;
                        case "Limit":
                            dic = ReadXMLElement(reader);
                            break;
                        case "Offset":
                            dic = ReadXMLElement(reader);
                            break;
                        case "TotalPages":
                            dic = ReadXMLElement(reader);
                            break;
                        case "RecordsReturned":
                            dic = ReadXMLElement(reader);
                            break;
                        case "PropertyDetails":
                            if (reader.NodeType != XmlNodeType.EndElement)
                            {
                                if (reader.HasAttributes)
                                {
                                    while (reader.MoveToNextAttribute())
                                    {
                                        if (reader.Name == "ID")
                                        {
                                            property.PropertyDetailsID = Convert.ToInt32(reader.Value);
                                        }
                                        else if (reader.Name == "LastUpdated")
                                        {
                                            try
                                            {
                                                property.LastUpdated = Convert.ToDateTime(reader.Value);
                                            }
                                            catch (Exception ex)
                                            {
                                                property.LastUpdated = DateTime.Now;
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case "ListingID":
                            if (reader.NodeType != XmlNodeType.EndElement)
                            {
                                if (reader.Name == "ListingID")
                                {
                                    string st = reader.ReadInnerXml();
                                    property.ListingID = reader.Value;
                                }
                            }
                            break;
                        case "AgentDetails":

                            if (reader.HasAttributes)
                            {
                                AgentModel agent = new AgentModel();

                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.Name == "ID")
                                    {
                                        agent.AgentDetailsID = Convert.ToInt32(reader.Value);
                                    }
                                }
                            }
                            break;
                    }
                }
                return model;
            }
            catch (Exception ex)
            {
                return null;
            }
        }