コード例 #1
0
        public bool UpdatePropertyDescriptionandImages()
        {
            bool   result  = false;
            long   id1     = 0;
            string HotelID = string.Empty;

            try
            {
                String hotelcode = string.Empty;

                List <CLayer.Property> objProperties   = BLayer.Property.GetAllGDSPropertiesWithOutData().ToList();
                List <CLayer.Property> objDescriptions = BLayer.Property.GetAllGDSPropertyDescriptionsWithOutData();
                //  List<CLayer.Property> objFormattedDescriptions = BLayer.Property.GetAllGDSPropertyFormattedDescriptionsWithOutData();
                List <CLayer.Property>               objTitles = BLayer.Property.GetAllGDSPropertyTitlesWithOutData();
                CLayer.GDSBookingDetails.Envelope    ss        = new CLayer.GDSBookingDetails.Envelope();
                CLayer.GDSBookingDetailsAdv.Envelope ssAdv     = new CLayer.GDSBookingDetailsAdv.Envelope();// ser.Deserialize<CLayer.GDSBookingDetailsAdv.Envelope>(hotel);
                long id = 0;
                foreach (var pitem in objProperties)
                {
                    try
                    {
                        #region Update Property Description
                        StringBuilder Description = new StringBuilder();
                        //Update property description start
                        Serializer ser = new Serializer();
                        id  = pitem.PropertyId;
                        id1 = id;
                        string HotelCode = pitem.HotelID;
                        HotelID = HotelCode;
                        string hotel = GetGDS_Hotel_Details(HotelCode);



                        ss = ser.Deserialize <CLayer.GDSBookingDetails.Envelope>(hotel);

                        DataTable dtHotel = BLayer.Property.GetHotelFormattedDescription(id);
                        string    FormattedDescription = string.Empty;
                        if (dtHotel.Rows.Count > 0)
                        {
                            foreach (DataRow dr in dtHotel.Rows)
                            {
                                FormattedDescription = Convert.ToString(dr["FormattedDescription"]);
                            }
                        }



                        if (string.IsNullOrEmpty(FormattedDescription))
                        {
                            FormattedDescription = GDSProcess.GDSFormatDescription.GetFormattedDescription(hotel);
                            BLayer.Property.GDSUpdatePropertyDescriptionFormatted(id, FormattedDescription, GDSProcess.GDSFormatDescription.StarRatings, "");
                        }
                        int LocalStarRating = APIUtility.GetStarRating(hotel);
                        if (LocalStarRating > 0)
                        {
                            BLayer.Property.GDSUpdatePropertyStarRatings(id, LocalStarRating);
                        }



                        if (ss.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents != null)
                        {
                            var TitleItem = objTitles.Where(x => x.HotelID == HotelCode).ToList();
                            if (TitleItem != null)
                            {
                                if (TitleItem.Count > 0)
                                {
                                    string Title = ss.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.HotelName;
                                    BLayer.Property.GDSUpdatePropertyTitle(id, Title);
                                }
                            }

                            #region Update Description Without Formatting

                            if (string.IsNullOrEmpty(FormattedDescription))
                            {
                                var DescriptionItem = objDescriptions.Where(x => x.HotelID == HotelCode).ToList();
                                if (DescriptionItem != null)
                                {
                                    if (DescriptionItem.Count > 0)
                                    {
                                        if (ss.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.HotelInfo != null)
                                        {
                                            var description = ss.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.HotelInfo.Descriptions;
                                            if (description != null)
                                            {
                                                var descriptionList = description.MultimediaDescriptions.MultimediaDescription;


                                                var Descriptions = from order in descriptionList
                                                                   where order.TextItems != null
                                                                   select order;
                                                string HotelDescription = string.Empty;
                                                foreach (var desc in Descriptions)
                                                {
                                                    if (desc.InfoCode != null)
                                                    {
                                                        foreach (var datas in desc.TextItems.TextItem.Description)
                                                        {
                                                            HotelDescription = HotelDescription + datas.__Text + "#256#";
                                                        }
                                                    }
                                                    // HotelDescription = HotelDescription + "<br>";
                                                }
                                                Description.Append(HotelDescription);

                                                BLayer.Property.GDSUpdatePropertyDescription(id, Description.ToString());
                                            }
                                        }
                                    }
                                }
                            }

                            #endregion

                            //update property description end
                            #endregion

                            #region Update Property Images old method
                            //  var ssw = ss.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.HotelInfo.Descriptions;
                            ////  var sswguest = ssAdv.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.HotelInfo.CategoryCodes.GuestRoomInfo.Where(x => x.Code == 28);

                            //  if (ssw!=null)
                            //  {
                            //      var sswList = ssw;

                            //      List<CLayer.PropertyFiles> picturelist = new List<CLayer.PropertyFiles>();
                            //      //var filteredOrders = from order in sswList
                            //      //                     where order.ImageItems != null
                            //      //                     select order;

                            //      int nos = 0;
                            //    BLayer.Property.DeleteGDSPropertyImages(id);

                            //      foreach (var item in sswList.MultimediaDescriptions.MultimediaDescription)
                            //      {
                            //          if (item.ImageItems != null)
                            //          {
                            //              var t = item.ImageItems.ImageItem;
                            //              if (t != null)
                            //              {
                            //                  foreach (var itemimg in t)
                            //                  {
                            //                      CLayer.PropertyFiles picture = new CLayer.PropertyFiles();
                            //                      picture.FileName = itemimg.ImageFormat.Where(x => x.DimensionCategory == "E").ToList()[0].URL;
                            //                      picture.PropertyId = id;
                            //                      picturelist.Add(picture);
                            //                      BLayer.Property.GDSSaveImageurl(id, picture.FileName);
                            //                      nos++;
                            //                      if (nos == PictureCount) break;
                            //                  }
                            //              }
                            //          }
                            //          if (nos == PictureCount) break;
                            //      }
                            //      if(picturelist.Count<8)
                            //      {
                            //          ssAdv = ser.Deserialize<CLayer.GDSBookingDetailsAdv.Envelope>(hotel);
                            //          var sswguest = ssAdv.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.HotelInfo.CategoryCodes.GuestRoomInfo.Where(x => x.Code == 28);
                            //          if (sswguest != null)
                            //          {
                            //              int PictureCount = 8 - picturelist.Count;
                            //              int ImgCounter = 0;
                            //              foreach (var item in sswguest)
                            //              {
                            //                  foreach (var itemAdv in item.MultimediaDescriptions)
                            //                  {
                            //                      if (itemAdv.ImageItems != null)
                            //                      {
                            //                          var t = itemAdv.ImageItems;
                            //                          if (t != null)
                            //                          {
                            //                              foreach (var itemimg in t)
                            //                              {
                            //                                  CLayer.PropertyFiles picture = new CLayer.PropertyFiles();
                            //                                  picture.FileName = itemimg.ImageFormat.Where(x => x.DimensionCategory == "E").ToList()[0].URL;
                            //                                  picture.PropertyId = id;
                            //                                  picturelist.Add(picture);
                            //                                  BLayer.Property.GDSSaveImageurl(id, picture.FileName);
                            //                                  ImgCounter++;
                            //                                  if (ImgCounter == PictureCount) break;
                            //                              }
                            //                          }
                            //                      }
                            //                      if (ImgCounter == PictureCount) break;
                            //                  }
                            //                  if (ImgCounter == PictureCount) break;
                            //              }
                            //          }
                            //      }


                            //  }
                            #endregion



                            #region update property contact numbers
                            //update GDS Property contact numbers start
                            CLayer.GDSBookingDetails.Envelope GDSBookingDetails = ss;
                            string Phone  = string.Empty;
                            string Mobile = string.Empty;
                            string Email  = string.Empty;
                            if (GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Emails != null)
                            {
                                Email = GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Emails.Email.ToString();
                            }
                            if (GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Phones != null)
                            {
                                if (GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Phones.Phone.Where(x => x.PhoneTechType == "1").Count() > 0)
                                {
                                    Phone = GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Phones.Phone.Where(x => x.PhoneTechType == "1").FirstOrDefault().PhoneNumber;
                                }
                                if (GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Phones.Phone.Where(x => x.PhoneTechType == "5").Count() > 0)
                                {
                                    Mobile = GDSBookingDetails.Body.OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents.HotelDescriptiveContent.ContactInfos.ContactInfo.Phones.Phone.Where(x => x.PhoneTechType == "5").FirstOrDefault().PhoneNumber;
                                }
                                if ((!string.IsNullOrEmpty(Phone)) || (!string.IsNullOrEmpty(Mobile)) || (!string.IsNullOrEmpty(Email)))
                                {
                                    BLayer.Property.GDSUpdatePropertyContactNumbers(id, Phone, Mobile, Email);
                                }
                            }
                            //update GDS Property Contact numbers end
                            //#region Transaction Log

                            //APIUtility.GenerateGDSTransactionLog("", "BulkImageandDescriptionSuccess", 0, (int)CLayer.ObjectStatus.GDSType.BulkHotelImageDescriptionUpdation, 0);

                            //#endregion Transaction log end
                            #endregion
                        }


                        #region UPDATE PROPERTY IMAGES
                        long ImageCount = BLayer.Property.GetGDSPropertyImagesCount(id);
                        if (ImageCount < 1)
                        {
                            BLayer.Property.DeleteGDSPropertyImages(id);
                            List <CLayer.PropertyFiles> pictlist = GetGDSImages(hotel, id);
                        }


                        #endregion

                        //    WriteToLog(HotelID);
                    }
                    catch (Exception ex)
                    {
                        //  LogHandler.AddLog("Error in-"+hotelcode);
                        WriteToLog(HotelID, true);
                    }
                    finally
                    {
                    }
                }
                result = true;
            }
            catch (Exception ex)
            {
                LogHandler.AddLog(ex.Message);
                string a = id1.ToString();
                result = false;

                throw ex;
            }
            return(result);
        }