Beispiel #1
0
        public async Task <HttpResponseMessage> GetProductDetailsBy_SuppName_SupHtlId_Format(string spname, string id, string format)
        {
            _database = MongoDBHandler.mDatabase();
            var accomodationsList  = _database.GetCollection <HotelsHotel>("Accommodations");
            var productMappingList = _database.GetCollection <ProductMapping>("ProductMapping");

            //FilterDefinition<HotelsHotel> filterAcco;
            //FilterDefinition<ProductMapping> filterPM;
            var idList = id.Split(',');

            XDocument doc = new XDocument();

            doc.Add(new XElement("Hotels"));

            Hotels             _Hotels      = new Hotels();
            List <HotelsHotel> _HotelsHotel = new List <HotelsHotel>();

            foreach (var hotelId in idList)
            {
                var searchResultPM = await productMappingList.Find(x => (x.SupplierCode.ToLower() == spname.ToLower() && x.SupplierProductCode.ToLower() == hotelId.ToLower())).ToListAsync();

                foreach (var resultPM in searchResultPM)
                {
                    var searchResultAcco = await accomodationsList.Find(x => (x.HotelId.ToLower() == resultPM.SystemProductCode.ToLower())).ToListAsync();

                    foreach (var hotel in searchResultAcco)
                    {
                        hotel.SupplierHotelID = hotelId;
                        _HotelsHotel.Add(hotel);
                    }
                }
            }

            _Hotels.Hotel = _HotelsHotel;

            HttpResponseMessage response = new HttpResponseMessage();

            if (format.ToLower() == "xml")
            {
                StringWriter  sw         = new StringWriter();
                XmlTextWriter tw         = null;
                XmlSerializer serializer = new XmlSerializer(_Hotels.GetType());
                tw = new XmlTextWriter(sw);
                serializer.Serialize(tw, _Hotels);
                sw.Close();
                if (tw != null)
                {
                    tw.Close();
                }

                response.Content    = new StringContent(sw.ToString(), Encoding.UTF8, "application/xml");
                response.StatusCode = HttpStatusCode.OK;
            }
            else if (format.ToLower() == "json")
            {
                response = Request.CreateResponse(HttpStatusCode.OK, _Hotels, "application/json");
            }
            response.StatusCode = HttpStatusCode.OK;
            return(response);
        }