Example #1
0
        //[OutputCache(Duration = 30, VaryByParam = "Id;cIn;cOut;sLocation;sRoomData", VaryByCustom = "User")] // Cached for 30 second
        public ActionResult Index(string Id, string cIn, string cOut, string sLocation, string sRoomData, string sRequestType)
        {
            PropDetailsM propDetails = new PropDetailsM();

            if (!string.IsNullOrEmpty(Id))
            {
                PropSearchRequestModel dbRequestParamModel = new PropSearchRequestModel();
                dbRequestParamModel.iVendorId = Id;
                var roomDataResult = new List <RoomData>();

                #region RoomOccupancySearch

                DataTable dtTblRoomOccupancySearch = new DataTable();

                dtTblRoomOccupancySearch.Columns.AddRange(new DataColumn[3]
                {
                    new DataColumn("ID", typeof(int)),
                    new DataColumn("iAdults", typeof(short)),
                    new DataColumn("children", typeof(short))
                });

                DataTable dtTblChildrenAgeSearch = new DataTable();
                dtTblChildrenAgeSearch.Columns.AddRange(new DataColumn[2]
                {
                    new DataColumn("ID", typeof(int)),
                    new DataColumn("Age", typeof(short))
                });

                if (!string.IsNullOrEmpty(cIn) && !string.IsNullOrEmpty(cOut))
                {
                    dbRequestParamModel.dtCheckIn  = DateTime.Parse(cIn);
                    dbRequestParamModel.dtCheckOut = DateTime.Parse(cOut);
                }
                else
                {
                    dbRequestParamModel.dtCheckIn  = DateTime.Now.Date.AddDays(1);
                    dbRequestParamModel.dtCheckOut = DateTime.Now.Date.AddDays(2);

                    cIn  = DateTime.Today.ToString("dd/MM/yyyy");
                    cOut = DateTime.Today.AddDays(1).ToString("dd/MM/yyyy");
                }

                dbRequestParamModel.bLogin    = User.Identity.IsAuthenticated;
                dbRequestParamModel.sCurrency = CurrencyCode;

                //Insert the room data in the table created
                if (!string.IsNullOrEmpty(sRoomData))
                {
                    roomDataResult = new JavaScriptSerializer().Deserialize <List <RoomData> >(sRoomData);
                }
                else
                {
                    roomDataResult.Add(new RoomData()
                    {
                        adult = 2, child = 0, room = 1, ChildAge = new List <ChildAge>()
                        {
                            new ChildAge()
                            {
                                Age = "0"
                            }
                        }
                    });
                }

                foreach (var room in roomDataResult)
                {
                    DataRow roomOccupancy = dtTblRoomOccupancySearch.NewRow();
                    roomOccupancy["ID"]       = room.room;
                    roomOccupancy["iAdults"]  = room.adult;
                    roomOccupancy["children"] = room.child;
                    dtTblRoomOccupancySearch.Rows.Add(roomOccupancy);

                    foreach (var child in room.ChildAge)
                    {
                        DataRow dtChildrenAge = dtTblChildrenAgeSearch.NewRow();
                        dtChildrenAge["ID"]  = room.room;
                        dtChildrenAge["Age"] = child.Age;
                        dtTblChildrenAgeSearch.Rows.Add(dtChildrenAge);
                    }
                }

                sRoomData = clsUtils.ConvertToJson(roomDataResult);


                #endregion

                string        roomIds              = string.Empty;
                List <string> roomIdsArr           = new List <string>();
                List <int>    hotelAmenitiesIdsArr = new List <int>();

                var ofrServiceCharge = BL_PropDetailsTG.GetOfrServiceCharge(dbRequestParamModel.dtCheckIn, dbRequestParamModel.dtCheckOut);

                //Get TG hotel details
                var hotelDetailsFromApi = clsSearchHotel.FetchHotelsDetailsByVendorId(false, dbRequestParamModel.iVendorId, dbRequestParamModel.dtCheckIn.ToString("yyyy-MM-dd"), dbRequestParamModel.dtCheckOut.ToString("yyyy-MM-dd"), dtTblRoomOccupancySearch, dtTblChildrenAgeSearch, roomDataResult);

                if (hotelDetailsFromApi != null && !string.IsNullOrEmpty(hotelDetailsFromApi.HotelCode))
                {
                    roomIdsArr = hotelDetailsFromApi.RoomDetails.Select(x => x.RoomId).ToList();
                    roomIds    = string.Join(",", roomIdsArr);

                    hotelAmenitiesIdsArr = hotelDetailsFromApi.HotelAmenities.Select(x => int.Parse(x.code)).ToList();

                    hotelDetailsFromApi.HotelAmenities = BL_PropDetailsTG.GetHotelAmenities(hotelAmenitiesIdsArr.ToArray());

                    if (hotelDetailsFromApi.GalleryImages.Count <= 0)
                    {
                        propDetails = BL_PropDetailsTG.GetPropertyDetails(dbRequestParamModel.iVendorId, roomIds);
                    }
                    else
                    {
                        propDetails = BL_PropDetailsTG.GetPropertyDetailsWithoutGallery(dbRequestParamModel.iVendorId, roomIds);
                    }
                }
                else
                {
                    propDetails = BL_PropDetailsTG.GetPropertyDetails(dbRequestParamModel.iVendorId, roomIds);
                }

                propDetails.ServiceChargeTG = ofrServiceCharge;

                propDetails.cStatus   = "A";
                propDetails.iVendorId = Id;

                propDetails.sRoomData             = sRoomData;
                propDetails.scheckIn              = cIn;
                propDetails.scheckOut             = cOut;
                propDetails.dtCheckIn             = dbRequestParamModel.dtCheckIn;
                propDetails.dtCheckOut            = dbRequestParamModel.dtCheckOut;
                hotelDetailsFromApi.RoomAmenities = propDetails.TG_Hotel.RoomAmenities;
                propDetails.TG_Hotel              = hotelDetailsFromApi;
                propDetails.sRequestType          = sRequestType;
                propDetails.Currency              = dbRequestParamModel.sCurrency;

                if (propDetails.TG_Hotel != null && propDetails.TG_Hotel.RoomAmenities != null)
                {
                    foreach (var roomId in roomIdsArr)
                    {
                        var tgRoom = hotelDetailsFromApi.RoomDetails.Where(x => x.RoomId == roomId).FirstOrDefault();
                        tgRoom.RoomAmenities = propDetails.TG_Hotel.RoomAmenities.Where(x => x.iRoomTypeId == tgRoom.RoomId).ToList();
                    }
                }

                Task.Run(() => BL_PropDetails.UpdateRecentViewAsync(propDetails.iPropId, User.Identity.GetUserId <long>()));

                ViewBag.dExchangeRate = 1;

                if (CurrencyCode != "INR")
                {
                    etblExchangeRatesM objExchange = BL_ExchangeRate.GetSingleRecordById("INR", CurrencyCode);
                    if (objExchange.dRate.HasValue)
                    {
                        ViewBag.dExchangeRate = objExchange.dRate.Value;
                    }
                }

                propDetails.Symbol = BL_ExchangeRate.GetSymbolByCurrencyCode(CurrencyCode);
            }
            return(View(propDetails));
        }